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

How do i find the local character's head in a server script?

Asked by
Zzverot 16
6 years ago
Edited 6 years ago

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?

0
it depends on the server script's parent. who's its parent? User#25069 0 — 6y
0
@Quezzert I've tried it in startergui, starterpack and workspace, but none of them woked Zzverot 16 — 6y

1 answer

Log in to vote
0
Answered by
Time_URSS 146
6 years ago
Edited 6 years ago

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!

Ad

Answer this question