What do you want to achieve? Keep it simple and clear!
I want my character’s walkspeed and jumpheight to be set to 0 when the player equips this tool.
What is the issue? Include screenshots / videos if possible!
It seems like the script isn’t working hence it’s not setting the walkspeed and jumpheight values
What solutions have you tried so far?
I’ve tried printing to the console after the if statement if player.Character then to see if that found a player’s character which it did. I also printed the walkspeed and jumpheight values and to my surprise it said in the output both were set to 0 when it really wasn’t. I also made sure that all of my scripts in the game aren’t altering my jumpheight or walkspeed in anyway that could be overriding this script. Lastly, I played my game on roblox.com and when I played it and equipped the tool it didn’t print anything to the developer console opposed to when I tested it in roblox studio when it did print successfully.
I don’t know what else I can try and I’m out of ideas. So I’ve come on here for some ideas/suggestions on what I should do.
-- This is an example Lua code block
script.Parent.Parent.Equipped:Connect(function()
local char = script.Parent.Parent.Parent
local player = game.Players:GetPlayerFromCharacter(char)
if player.Character then
local isQb = Instance.new("BoolValue",player.Character)
isQb.Name = "isQB"
isQb.Value = true
player.Character.Humanoid.WalkSpeed = 0
player.Character.Humanoid.JumpHeight = 0
script:Destroy()
end
end)
Without too much information, it is possible that you are using a local script when you should not be. Otherwise, I am not exactly sure what the problem is.
Are you sure that there are no other scripts that could be over-riding this?
I’m using a server script located inside a model in the workspace. I am very sure that there are no other scripts overriding it because I searched with the built-in roblox tool that allows you to search a specified word in any script in the game and none of the scripts showed me setting the walkspeed beside this script. I am just clueless.
My guess is as good as yours. Try leaving a print at every stage to see where the code goes wrong, and I put a wait() function right before the script destroys itself. It should not need that as part of the script, but just in case the script may be laggy or problematic.
-- This is an example Lua code block
script.Parent.Parent.Equipped:Connect(function()
print("Stage 1")
local char = script.Parent.Parent.Parent
local player = game.Players:GetPlayerFromCharacter(char)
if player.Character then
print("Stage 2")
local isQb = Instance.new("BoolValue",player.Character)
isQb.Name = "isQB"
isQb.Value = true
print("Stage 3")
player.Character.Humanoid.WalkSpeed = 0
player.Character.Humanoid.JumpHeight = 0
print("Stage 4")
wait()
print('Stage 5')
script:Destroy()
end
end)
If one of these does not show up in the ‘Output’ log, then we know where to read between the lines.
It’s worth noting that this tool that has the script inside of it starts out in replicated storage then I’m cloning it into the workspace. Even with that said it should still work. As you can see the output in roblox studio prints this. But it still doesn’t alter my walkspeed or jumpheight.
Now when I test inside a game on roblox not in studio and I check the developer console, it doesn’t even show the prints at all.
It’s worth noting that this tool that has the script inside of it starts out in replicated storage then I’m cloning it into the workspace.
Oh, that is literally it. Scripts do not work inside of ReplicatedStorage. Unless the script is put inside of the tool before the player equips it, in which that case it should still work!
I understand that scripts don’t work in ReplicatedStorage. But I’m cloning the tool into the workspace for my player to pick up then the script should execute when my player equips the tool.