#Trying to get the player in a ServerScript, but it just breaks the script, no errors.

2 messages · Page 1 of 1 (latest)

cedar light
#
alreadydone = false
local function Open(hit : BasePart)
    local players = game:GetService("Players")
    if alreadydone == false then
        if hit and hit.Parent and hit.Parent:IsA("Tool") and hit.Parent:GetAttribute("Kind") == "PurpleLockedKey" then
            game.Players.PlayerAdded:Connect(function(player)
                print(player.Name)
                warn(player.DisplayName)
                alreadydone = true
                game.ReplicatedStorage.KeyIsLocked:FireClient(player)
                local folder = game.Workspace.Doors
                local path = folder.DownstairsDoor
                path.Lock:Play()
            end)
        end
    end
end
script.Parent.Touched:Connect(Open)```
(SERVERSCRIPT) I'm trying to get the player in a serverscript, but it just breaks the script again. Any idea what's wrong and how to fix it? No errors, not anything.
onyx terrace
#

PlayerAdded only fires when a player joins the game. You are trying to find a player that is already in the game, hence why calling PlayerAdded doesn't work.