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

Server script can't find players character in workspace?

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

✓ Accepted answer

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

2 comments

0

Yes, thankyou so much

0

marking this as answered since you said that.

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