Player doesn't change its walkspeed

Hey Devs! I want to make the player frozen when the prompt was triggered and it doesn’t work. I tried making it only with frame and it perfectly works. (The script for walkspeed is from DevHub)

image

h.WalkSpeed should be player.Character.Humanoid.WalkSpeed, Triggered returns the player who triggered the prompt, use that to get their humanoid to change the walkspeed

Also remove the code for player1, char, and h

1 Like

I agree with @EmbatTheHybrid to an extent but you also need to include sanity checks to see if the player who triggered the prompt is the local player. You have to do this because local scripts can only manage the GUI of the player it is attached to. The revised code should be what is below. The only thing you might have to change is the path of the prompt. Hopefully this works!

local prompt = game.Workspace.Model.ProximityPrompt
local localPlayer = game.Players.LocalPlayer
local humanoid = localPlayer.Character.Humanoid
local playerGui = localPlayer.Gui
local screenGui = playerGui.screenGui
local swordShop = screenGui.SwordShop    

prompt.Triggered:Connect(function(player)
if player == localPlayer then
       swordShop.Visible = true
       humanoid.WalkSpeed = 0
end)

This code should be in a LocalScript inside of the StarterPlayerScripts.

2 Likes

I actually tested it and it doesn’t work. There’s an error with .Humanoid in the 3rd line and you need to add one more “end” on the end.

Alright, sorry I don’t have time to test it right now. Maybe try

local humanoid = localPlayer.CharacterAdded:Wait():WaitForChild("Humanoid")

You missed an end in your if statement

Ah, thanks. It’s annoying to code without autocomplete in studio.

Oh and I can already see that local playerGui = localPlayer.Gui will not work, because it doesn’t know what does it mean. (Sorry for not helping and you probably think that this guy only wants copy and paste scripts and he doesn’t appreciate my work, I’m just a newbie at scripting. :slight_smile: )

Sorry, it should be localPlayer.PlayerGui. I’m on a Chromebook right now so I don’t have studio to test. Of course not! We all start somewhere. I didn’t get into the DevForum until I was a little bit more advanced in scripting but I have tons of posts like this on ScriptingHelpers.

1 Like

It worked! I’m so happy that you helped me. Have a nice day!

1 Like

Of course! I’m so glad I could help! Good luck on your game! :smiley: