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

Check for players code not working properly?

I am currently working on a time stop script that anchors all players for 12 seconds and unanchors them. However, the time stop movement is where I'm having the trouble. I'm having a server script check if any players have a certain user name. If they do, then they will be unanchored; but whenever i check for the player, the script doesn't fire OR print anything even though I have a localscript fire the event. Here is the script if needed:

game.ReplicatedStorage.PlayerCheck.OnServerEvent:Connect(function()
	
game.Players.PlayerAdded:Connect(function(player)
		
		player.CharacterAdded(function(character)
if player.Name == "Crimsonknightzone" then
	print("Unfreezing")
		end)
end)
end)

bonus points if you can [somehow] fit the check for player into my TS script (Optional) :)

game.ReplicatedStorage.FreezePop.OnClientEvent:Connect(function()
	local player = game.Players.LocalPlayer
	local character = player.Character
	if not character or not character.Parent then
    	character = player.CharacterAdded:wait()
end
	if character then 
		character.Torso.Anchored = true
		local Larm = character["Left Arm"]
		local Rarm = character["Right Arm"]
		local Lleg = character["Left Leg"]
		local Rleg = character["Right Leg"]
		
		Larm.Anchored = true
		Rarm.Anchored = true
		Lleg.Anchored = true
		Rleg.Anchored = true
		character.Head.Anchored = true
		
		if player.Character == "Crimsonknightzone" then
			print("Player is fit for TS, Removing constraints")
		end
		
		wait(12)
		
		local sound = game.Workspace.TSRes
		sound:Play()
		Larm.Anchored = false
		Rarm.Anchored = false
		Lleg.Anchored = false
		Rleg.Anchored = false
		character.Torso.Anchored = false
		character.Head.Anchored = false
		
	end
	end)

2 answers

If you are in the remote event, then chances are the player is already loaded. Do this to wait for a character:

local char = player.Character or player.CharacterAdded:Wait()

if char then
	--Your code to unanchor
end

Hope this helped!

If all you're trying to do is check if any of the players' name is equal to a certain name then that is very easy to do, you can just loop through the Players folder and check if any of the Player's names are equal to a certain name.

Server Script:

local Players = game:GetService("Players")

game.ReplicatedStorage.PlayerCheck.OnServerEvent:Connect(function()
	
	for i,v in pairs(Players:GetChildren()) do
		
		if v.Name == "Crimsonnightzone" then 
			local player = v
			local character = player.Character
			print("Unfreezing "..player.Name)
	
		end
	end
end)

However for your Local Script, you can see if this will work:

game.ReplicatedStorage.FreezePop.OnClientEvent:Connect(function()
    local player = game.Players.LocalPlayer
    local character = player.Character or player.CharacterAdded:Wait()
    if not character or not character.Parent then
        character = player.CharacterAdded:wait()
end
    if character then 
        character.Torso.Anchored = true
        local Larm = character["Left Arm"]
        local Rarm = character["Right Arm"]
        local Lleg = character["Left Leg"]
        local Rleg = character["Right Leg"]

        Larm.Anchored = true
        Rarm.Anchored = true
        Lleg.Anchored = true
        Rleg.Anchored = true
        character.Head.Anchored = true

        if player.Character.Name == "Crimsonknightzone" then
            print("Player is fit for TS, Removing constraints")
        end

        wait(12)

        local sound = game.Workspace.TSRes
        sound:Play()
        Larm.Anchored = false
        Rarm.Anchored = false
        Lleg.Anchored = false
        Rleg.Anchored = false
        character.Torso.Anchored = false
        character.Head.Anchored = false

    end
    end)

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