Up untill now my script wasn't working but had no errors. I figured out it was because i was doing it in a local script, but in a server script you cant target localplayer or localplayer.character.
What i want to do is to place a part onto the characters head. I used game.Workspace.TestPart.CFrame = game.Players.LocalPlayer.Character.Head.CFrame but this only works in localscripts. How can i do this in a server script?
COMMUNITY QUESTION
How do i find the local character's head in a server script?
1 answer
In your case, I'd use a remoteEvent, to take the player from a local script, call a serverscript, ans the serverscript would find the character thing. I'd make you an example.
-- Local script
local player = game.Players.LocalPlayer
local event = game:GetService("ReplicatedStorage"):WaitForChild("EventName")
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)
event:FireClient(player)
end)
end)
then
-- Server Script
local event = game:GetService("ReplicatedStorage"):WaitForChild("EventName")
event.OnClientEvent:Connect(function(player)
local character = game.Workspace[player.Name].Head
-- If you want to attach a part to the Head, do it here.
end)
This example shows you how does the script gets the head of a character when a player joins.
If you've any problems, DM me in Discord, Username: Time_UR$$#6385
Hope it works!
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
it depends on the server script's parent. who's its parent?
@Quezzert I've tried it in startergui, starterpack and workspace, but none of them woked