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

How to make a clickable brick add a trail to your character?

I've been trying to do this for a while now but hasn't worked out that well... I'm using this code currently:

local player = game.Players.LocalPlayer.Character
local redtrail = game.Workspace.RedTrailButton.ClickDetector	
		redtrail.MouseClick:connect(function()
		local trail = game.ServerStorage.RedTrail:Clone()
		trail.Parent.Parent = game.Workspace.player.Head
		local attachment0 = Instance.new("Attachment", player.Head)
		attachment0.Name = "TrailAttachment0"
		local attachment1 = Instance.new("Attachment", player.HumanoidRootPart)
		attachment1.Name = "TrailAttachment1"
		trail.Attachment0 = attachment0
		trail.Attachment1 = attachment1
	end)

This is a LocalScript, because if it was a normal script it would return as a nil value which is annoying.

But when I click the brick it never gives me the trail, it also gives me no errors in the console when clicked. Any help on how to make it give me a trail?

Also, everything is in the right place. The "player" bit refers to your character so that it can add it to the Torso area.

6 comments

0

Maybe use a weld

0

When I make it so the trail is given when the player joins, it works. But then when I use a button, it won't give one. I'm not sure how to use a Weld, sorry I am quite bad at LUA.

0

Weld is an Instance it can hold 2 things together in weird position

0

Attachment0 and attachment1 need an attachment instance. Don't ask my why it can't use BaseParts or anything, just deal with it. Also, a trail is NOT a BasePart.

0

Also, it is Lua, not LUA.

0

You can't access ServerStorage through a LocalScript, why has no one pointed that out?

1 answer

This should be a regular script as you can't access ServerStorage from the client, hence ServerStorage.

local redtrail = game.Workspace.RedTrailButton.ClickDetector    
redtrail.MouseClick:connect(function(player) -- use the mouseclick's player argument
        local trail = game.ServerStorage.RedTrail:Clone()
        trail.Parent = player.Character.Head
        local attachment0 = Instance.new("Attachment", player.Head)
        attachment0.Name = "TrailAttachment0"
        local attachment1 = Instance.new("Attachment", player.HumanoidRootPart)
        attachment1.Name = "TrailAttachment1"
        trail.Attachment0 = attachment0
        trail.Attachment1 = attachment1
end)

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