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

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

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)

2 comments

0

What is the rest of the script and where is it located?

0

thats all the script and it's inside a dummys humanoid root part

1 answer

✓ Accepted answer

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 comment

1

Thanks so much! it works

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