i wrote this script which gets an attribute from the player, checks if its true or not, and sets the jump power accordingly, but it doesnt work. If you know what the issue is, please help me ( i am new to scripting )
local plr = game.Players.LocalPlayer
plr.CharacterAdded:Wait()
local char = plr.Character
local nojump = char:GetAttribute("NoJump")
local runservice = game:GetService("RunService")
runservice.Heartbeat:Connect(function()
if nojump then
char:WaitForChild("Humanoid").JumpPower = 0
end
if not nojump:GetAttribute("NoJump") then
char:WaitForChild("Humanoid").JumpPower = 50
end
end)
If the script is inside StarterCharacterScripts it will be copied inside the character after it loads which means this line may yield the script forever:
plr.CharacterAdded:Wait()
Another issue is that you only get the NoJump value once(outside the event loop) so it wont update if the value changes.
Also, your script does some weird things like using WaitForChild in the event loop. Here’s a more clear version of your code that might work:
--LocalScript inside StarterCharacterScripts
local plr = game.Players.LocalPlayer
local char = script.Parent
local hum = char:WaitForChild("Humanoid")
function valChanged()
hum.JumpPower = (char:GetAttribute("NoJump") and 0) or 50
end
--Instead of checking every frame, we only check at script start and when the value changes
valChanged()
char:GetAttributeChangedSignal("NoJump"):Connect(valChanged)
Why go through all this hell when you can just change the script parent? The script only interacts with the player character so I don’t see why it shouldn’t be in StarterCharacterScripts.
Also local scripts don’t run in workspace because the game simply can’t figure out to which player/character they belong to.