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

Server script can't find players character in workspace?

Asked by 3 years ago

I'm using a local script in starterGui to send a players name to a server script using a remote event, everything is working so far, the server script is getting the players name but it can't find the players character in the workspace, It seems like it should and it's probably something really simple I just can't stop, could someone tell me why it won't?

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Remote = ReplicatedStorage:WaitForChild("Remote")


local function Event(player)
    print(player)

local PlayerCharacter = game.Workspace:WaitForChild(player)
print(PlayerCharacter)

local Headlamp = PlayerCharacter:FindFirstChild("Headlamp")
local LightEmitter = Headlamp:FindFirstChild("LightEmitter")
local Spotlight = LightEmitter:FindFirstChild("SpotLight")

    if Spotlight.Enabled == false then
        Spotlight.Enabled = true
    else
        if Spotlight.Enabled == true then
            Spotlight.Enabled = false
        end

end
end

Remote.OnServerEvent:Connect(Event)

It's on line 9

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

player is a Player instance, not a string. Either change it to

game.Workspace[player.Name]

OR just get the character from the player.

Char = player.Character or player:CharacterAdded:wait()

Hope this helps :3

0
Yes, thankyou so much CheeseBallGuy11 12 — 3y
0
marking this as answered since you said that. greatneil80 2647 — 3y
Ad

Answer this question