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

Why can't i grab my Character from a server script?

Asked by 4 years ago

I'm trying to weld part0 to the characters head but i can't seem to get the character

function onClicked()
local Character = Player.Character or Player.CharacterAdded:Wait()
local w = Instance.new("Weld")
w.Parent = script.Parent
w.Part1 = script.Parent
w.Part0 = Player.Head
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
0
What is the rest of the script and where is it located? ScriptedEli 101 — 4y
0
thats all the script and it's inside a dummys humanoid root part Deinonychusaurus 21 — 4y

1 answer

Log in to vote
0
Answered by
Hypgnosis 186
4 years ago

ClickDetector event has a PlayerWhoClicked paramater.

So, by adding "Player" into the parameter section of the function, this should work:

function onClicked(Player)
    local Character = Player.Character or Player.CharacterAdded:Wait()
    local w = Instance.new("Weld")
    w.Parent = script.Parent
    w.Part1 = script.Parent
    w.Part0 = Player.Head
end

script.Parent.ClickDetector.MouseClick:Connect(onClicked)
1
Thanks so much! it works Deinonychusaurus 21 — 4y
Ad

Answer this question