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

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

Asked by 6 years ago

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.

0
Maybe use a weld Lolamtic 63 — 6y
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. SimpleArrows -5 — 6y
0
Weld is an Instance it can hold 2 things together in weird position Lolamtic 63 — 6y
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. hiimgoodpack 2009 — 6y
View all comments (2 more)
0
Also, it is Lua, not LUA. hiimgoodpack 2009 — 6y
0
You can't access ServerStorage through a LocalScript, why has no one pointed that out? creeperhunter76 554 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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)
Ad

Answer this question