So I have an admin panel for my game and i have a button. That is meant to freeze the player that the person selected (For Example The Username is typed out In a textbox and then you can freeze the player.) but when I click The "freeze player Button" it does not work I've made the freeze button Filtering enabled so its not that here is part of the script that is meant to do the freeze player event.
game.ReplicatedStorage.Fe.Freeze.OnServerEvent:Connect(function(plr, player) --Checks if the Freeze Remote Event Is Triggered for i, v in pairs (game.Workspace:GetChildren()) do if v.Name == player then player.Humanoid.WalkSpeed = 0 print(player)--Printing the player name end end end)
I would be very Thankful If Anyone would help me with this issue Thanks! Sorry for my bad English.
Does the script print the name of the player who the admin wanted to freeze? If so. here's the problem:
the "player" variable only stores the name of the player as a string, not the character. So when you want to freeze the player, the script tries to freeze a string which obviously doesn't work.
I would also recommend using FindFirstChild() to find the target player rather than using a loop.
This script should do the job:
game.ReplicatedStorage.Fe.Freeze.OnServerEvent:Connect(function(plr, player) if game.Workspace:FindFirstChild(player) and game.Workspace:FindFirstChild(player).Humanoid == true then game.Workspace:FindFirstChild(player).Humanoid.WalkSpeed = 0 end end)