I have a GUI that appears while touching a part and I want it to make the player slower when the GUI is visible but the script I tried isn’t working, Can someone tell me what the problem is or fix the script?
do this
local player = game.Players.LocalPlayer
player.Character.Humanoid.WalkSpeed = num
Also you should never loop this if youre just setting it a direct number. You dont even need a remote event to do this. This entire script could be made local and would be much easier and better on performance.
If the default gui is visible = false, the loop will skip, also this is misspelled
local player = game:GetService("Players").LocalPlayer
while task.wait() do
if not script.Parent.Frame.Visible then continue end
player.Character.Humanoid.WalkSpeed = 10
To the OP, you know when the frame is changing it’s visibility! So instead of doing a loop forever, why not just change the walkspeed whenever the frame is set to visible and reset it after it’s invisible…?
local player = game.Players.LocalPlayer
local character = player.Character
if not character or not character.Parent then
character = player.CharacterAdded:wait()
end
local Humanoid = character:WaitForChild("Humanoid")
game.ReplicatedStorage.ShowMoneyGui.OnClientEvent:Connect(function()
script.Parent.Frame.Visible = true
Humanoid.WalkSpeed = 10
end)
game.ReplicatedStorage.HideMoneyGui.OnClientEvent:Connect(function()
script.Parent.Frame.Visible = false
Humanoid.WalkSpeed = 16
end)
Change the walkspeed client side > you practically are never in a situation where you need the server to check the walkspeed of the humanoid. Like literally. Stop giving people bad ideas > its just considered bad programming to change walkspeed server side. You literally never need to check it server side and even if you did > just use fireclient to send a remote from the server. Theres literally 0 top programmers that change it server side. Almost all top games handle effects client side because its 100% better on performance. No one cares about the speed value replicating to server side > all that matters is the actual walkspeed gets changed.
Edit - The only situation that I could logically think of that you would need to check the walkspeed value is an anti exploit script > I also constantly make abilities that involve changing the walkspeed. So again theres literally no reason to do it server side unless youre trying to make anti exploit stuff, but even then you can still do the check client side xd.