generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Functions only while touching?

Previous Thread :: Next Thread 
KodakKid3 is not online. KodakKid3
Joined: 25 Dec 2008
Total Posts: 2860
21 Sep 2013 06:15 PM
When you touch this button, your walkspeed becomes 10. I'm wanting it to only be 10 while you're stepping on the button, then go back to normal. Have tried more than a couple ways to do it, none have worked. Help?

function onHumanoid(part)
local humanoid = part.Parent:FindFirstChild("Humanoid")
if (humanoid ~= nil) then
humanoid.WalkSpeed = 10
end
end

script.Parent.Touched:connect(onHumanoid)
Report Abuse
Soquick is not online. Soquick
Joined: 01 Nov 2012
Total Posts: 1497
21 Sep 2013 06:18 PM
script.Parent.TouchEnded:connect(function(pt)
pcall(function() pt.Parent.Humanoid.WalkSpeed = 16 end)
end)
Report Abuse
KodakKid3 is not online. KodakKid3
Joined: 25 Dec 2008
Total Posts: 2860
21 Sep 2013 06:28 PM
Thanks.

-pls stahp am cryin
Report Abuse
KodakKid3 is not online. KodakKid3
Joined: 25 Dec 2008
Total Posts: 2860
21 Sep 2013 06:32 PM
Er, scratch that, your walkspeed doesn't return to normal after you step off of it. I'll be working on it to see if I can find a solution, but I doubt I'll be able to.

-pls stahp am cryin
Report Abuse
memorycode is not online. memorycode
Joined: 24 Sep 2011
Total Posts: 3322
21 Sep 2013 06:53 PM
script.Parent.TouchEnded:connect(function(pt)
pcall(function() pt.Parent.Humanoid.WalkSpeed = 16 else pt.Parent.Humanoid.Walkspeed = 8 end)
end)


Just alter the eight to desired.

(I don't know if this works, pcall hates me.)
Report Abuse
crazyman32 is not online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
21 Sep 2013 07:24 PM
Why are you guys using pcall? No reason to wrap it in such a way when you can easily check if it's a player

script.Parent.Touched:connect(function(part)
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if (player) then
player.Character.Humanoid.WalkSpeed = 10
end
end)

script.Parent.TouchEnded:connect(function(part)
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if (player) then
player.Character.Humanoid.WalkSpeed = 16
end
end)
Report Abuse
KodakKid3 is not online. KodakKid3
Joined: 25 Dec 2008
Total Posts: 2860
21 Sep 2013 07:28 PM
Mem, I can't use yours, because people in the game will have multiple walkspeeds, not all 16. I'll test out the other one when I can, it looks right.

-pls stahp am cryin
Report Abuse
KodakKid3 is not online. KodakKid3
Joined: 25 Dec 2008
Total Posts: 2860
21 Sep 2013 07:34 PM
Er, Crazy, can't use yours either, for the same reason.

-pls stahp am cryin
Report Abuse
KodakKid3 is not online. KodakKid3
Joined: 25 Dec 2008
Total Posts: 2860
21 Sep 2013 08:58 PM
bump pls
Report Abuse
Soquick is not online. Soquick
Joined: 01 Nov 2012
Total Posts: 1497
21 Sep 2013 09:04 PM
cw = 16
script.Parent.Touched:connect(function(part)
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if (player) then
cw = (player.Character.Humanoid.WalkSpeed)
player.Character.Humanoid.WalkSpeed = 10
end
end)
script.Parent.TouchEnded:connect(function(part)
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if (player) then
player.Character.Humanoid.WalkSpeed = cw
end
end)
Report Abuse
KodakKid3 is not online. KodakKid3
Joined: 25 Dec 2008
Total Posts: 2860
21 Sep 2013 09:06 PM
Erm, Soquick, cannot use that either, due to the same reason as the two above. People playing the game might have 14 walkspeed, might have 16, might have 18 or 20. It could be anything. It just needs to go back to normal after they're off the piece.

-pls stahp am cryin
Report Abuse
Soquick is not online. Soquick
Joined: 01 Nov 2012
Total Posts: 1497
21 Sep 2013 09:08 PM
CW changes.
Report Abuse
KodakKid3 is not online. KodakKid3
Joined: 25 Dec 2008
Total Posts: 2860
21 Sep 2013 09:09 PM
Why would cw initially = 16?

-pls stahp am cryin
Report Abuse
Soquick is not online. Soquick
Joined: 01 Nov 2012
Total Posts: 1497
21 Sep 2013 09:10 PM
--Just in case 2 people on brick at once--
script.Parent.Touched:connect(function(part)
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if (player) then
ol = Instance.new("IntValue", player.Character.Parent)
ol.Name = "OldSpeed"
ol.Value = (player.Character.Humanoid.WalkSpeed)
player.Character.Humanoid.WalkSpeed = 10
end
end)
script.Parent.TouchEnded:connect(function(part)
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if (player) then
player.Character.Humanoid.WalkSpeed = player.Character.OldSpeed.Value
player.Character.OldSpeed:Destroy()
end
end)
Report Abuse
KodakKid3 is not online. KodakKid3
Joined: 25 Dec 2008
Total Posts: 2860
21 Sep 2013 09:13 PM
And So, neither one is working. THey change the speed, but don't change it back.

-pls stahp am cryin
Report Abuse
Soquick is not online. Soquick
Joined: 01 Nov 2012
Total Posts: 1497
21 Sep 2013 09:15 PM
script.Parent.Touched:connect(function(part)
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if (player) then
ol = Instance.new("IntValue", player.Character.Parent)
ol.Name = "OldSpeed"
ol.Value = (player.Character.Humanoid.WalkSpeed)
player.Character.Humanoid.WalkSpeed = 10
end
end)
script.Parent.TouchEnded:connect(function(part)
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if (player) then
player.Character.Humanoid.WalkSpeed = player.Character:FindFirstChild("OldSpeed", true).Value
player.Character:FindFirstChild("OldSpeed", true):Destroy()
end
end)
Report Abuse
travddm is not online. travddm
Joined: 29 Mar 2012
Total Posts: 926
21 Sep 2013 09:15 PM
Hmm..

script.Parent.Touched:connect(OnTouched)

function OnTouched (part)
if part.Parent:findFirstChild("Humanoid")~=nil then
local speed=part.Parent.Humanoid.WalkSpeed
part.Parent.Humanoid.WalkSpeed=10
end
script.Parent.TouchEnded:connect(function(peice)
if peice.Parent==part.Parent then
peice.Parent.Humanoid.WalkSpeed=speed
end
end)
end
Report Abuse
travddm is not online. travddm
Joined: 29 Mar 2012
Total Posts: 926
21 Sep 2013 09:17 PM
Soquick's seems much better than mine, though mine still would work...
Report Abuse
KodakKid3 is not online. KodakKid3
Joined: 25 Dec 2008
Total Posts: 2860
21 Sep 2013 10:32 PM
Soquick, yours will change the walkspeed to 10, but not bck.

And Trav, yours didn't work at all.

-pls stahp am cryin
Report Abuse
travddm is not online. travddm
Joined: 29 Mar 2012
Total Posts: 926
21 Sep 2013 10:33 PM
ReallyNao?
Report Abuse
travddm is not online. travddm
Joined: 29 Mar 2012
Total Posts: 926
21 Sep 2013 10:34 PM
I must have something wrong.. Never used TouchEnded before, care to spew the output?
Report Abuse
KodakKid3 is not online. KodakKid3
Joined: 25 Dec 2008
Total Posts: 2860
21 Sep 2013 10:36 PM
20:36:38.826 - attempt to call a nil value
20:36:38.834 - Disconnected event because of exception
Report Abuse
KodakKid3 is not online. KodakKid3
Joined: 25 Dec 2008
Total Posts: 2860
22 Sep 2013 08:34 AM
qq
Report Abuse
KodakKid3 is not online. KodakKid3
Joined: 25 Dec 2008
Total Posts: 2860
22 Sep 2013 11:39 AM
Does anyone know why the above don't work?

-pls stahp am cryin
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image