Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Freeze Player button does not work help?

Asked by 4 years ago

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.

1 answer

Log in to vote
1
Answered by
sydre 229 Moderation Voter
4 years ago
Edited 4 years ago

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)
0
consider that if :FindFIrstChild Returns nil,then the script will break, other wise good job SoftlockedUnderZero 668 — 4y
0
oh yeah that's true, fixed it sydre 229 — 4y
Ad

Answer this question