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

Not working: Trail attaches when playerclicks?

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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!

Ad

Answer this question