Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Freeze Player button does not work help?

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

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)

2 comments

0

consider that if :FindFIrstChild Returns nil,then the script will break, other wise good job

0

oh yeah that's true, fixed it

This discussion is preserved as it was. New answers, comments, and votes are closed.