Hi Guys. Just made a simple Gui Button script below that changes player walkspeed.
How do I amend this so that it only changes walkspeed on CharacterAdded so as to only change walkspeed on respawn instead of immediately...?
Tried a bunch of stuff and it feels like it should be simpler than I'm making it out to be..
Thanks in advance!
Player = script.Parent.Parent.Parent.Parent.Parent Cost = 1 script.Parent.MouseButton1Click:connect(function() if Player:findFirstChild("skills") then if Player.skills.Talents.Value >= Cost then Player.skills.Talents.Value = Player.skills.Talents.Value -Cost script.Parent.Parent.Parent.Parent.Parent.Character.Humanoid.WalkSpeed = script.Parent.Parent.Parent.Parent.Parent.Character.Humanoid.WalkSpeed + 2.5 script.Parent.Parent.DasherBought.Visible = true end end end)
Try this:
Player = script.Parent.Parent.Parent.Parent.Parent Cost = 1 script.Parent.MouseButton1Click:connect(function() if Player:findFirstChild("skills") then if Player.skills.Talents.Value >= Cost then Player.skills.Talents.Value = Player.skills.Talents.Value -Cost if(player.Character:FindFirstChild("walkAddition") == nil) then local player = script.Parent.Parent.Parent.Parent.Parent local human = player.Character.Humanoid local walkAddition = Instance.new("NumberValue",player) walkAddition.Name = "walkAddition" walkAddition.Value = 2.5 end script.Parent.Parent.DasherBought.Visible = true end end end end) game.Players.PlayerAdded:connect(function(plr) plr.CharacterAdded:connect(function(character) local walk = plr:FindFirstChild("walkAddition") if(walk ~= nil) then character.Humanoid.WalkSpeed = character.Humanoid.WalkSpeed + walk.Value walk:Destroy() end end) end)
Basically what happens, is if the button is pressed it adds an object to the player, and when the character respawns it detects if the object is there, and if it is it'll change the walk speed and delete it!
If you need any more help just ask! :D
This should help.
`` ****NOTE:**** I typed this in the scripting helpers website, so there may be some capitalization errors. I also did some code-writing cleanups.
`` ****IMPORTANT!**** This script looks like it needs to be in a client-side (Local) script. Make sure it is there.
--[[ **HOW TO make good code:** - Indent! - If you happen to be sharing on Scripting Helpers, comment (using "--" for short (rest of line) comment, and "--[[ to open a long comment, which goes on until "]]--" is used.)! - Use some print functions to tell you what happened in the code for easy troubleshooting! - You made a player variable, so use it! - Please, use "local" before your variables. ]]-- --------------------------------- ---------[ Variables ]-------- --------------------------------- local Player = script.Parent.Parent.Parent.Parent.Parent local Cost = 1 local hasGivenBoost = false -- used in the "once only" section. ---------------------------- ---------[ Code ]-------- ---------------------------- script.Parent.MouseButton1Click:connect(function() if Player:FindFirstChild("skills") then if Player.skills.Talents.Value >= Cost then Player.skills.Talents.Value = Player.skills.Talents.Value -Cost print(Player.Name.."'s talent is the greater than the cost.") Player.CharacterAdded:connect(function(c) -- detects when the player's character was added (every time) --[[ -- Remove then long comment things ("--[[" and "]]--") if you only want it to do it once. If hasGivenBoost = false then hasGivenBoost = true print(Player.Name.." just got the speed boost.) else print(Player.Name.." tried to get it after they already got the boost") return end ]]-- print(Player.name.."'s character was added") c.Humanoid.WalkSpeed = c.Humanoid.WalkSpeed + 2.5 -- Add the character's speed boost script.Parent.Parent.DasherBought.Visible = true -- turns the thingy that says that it was bought to be able to be seen. end) end end end)