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

Not working: Trail attaches when playerclicks?

I am making a system where when a player clicks a part, a trail gets attached to them.

I have a part in the workspace named "Part" In the part there is a clickdetector named "ClickDetector" In the workspace there is a remote event named "MyClickDetector" In the remote event there is a script named "Script" In the starter gui there is a localscript named "LocalScript" there is a trail in the ServerStorage

This is the LocalScript

local clickdetector = game.Workspace.Part.ClickDetector
clickdetector.MouseClick:Connect(function()
	game.Workspace.MyClickDetector:FireServer()
end)

This is the script in the remote event

game.Workspace.MyClickDetector.OnServerEvent:Connect(function()
        --not sure how to make it attach on the player that has clicked the part
		local trail = game.ServerStorage.Trail:Clone()
		trail.Parent = char.Head
		local attachment0 = Instance.new("Attachment",char.Head)
		attachment0.Name = "TrailAttachment0"
		local attachment1 = Instance.new("Attachment",char.HumanoidRootPart)
		attachment1.Name = "TrailAttachment1"
		trail.Attachment0 = attachment0
		trail.Attachment1 = attachment1
end)

1 answer

✓ Accepted answer

You don't even need the LocalScript. The ClickDetector has a player parameter that you can use. Example:

game.Workspace.MyClickDetector.MouseClick:Connect(function(player)
--code
end

I hope this helps and have a great day scripting!

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