I’ve been wanting to know about how to make it so, when you press a button, a trail clones into a player. I already know how to add a trail when a player enters the game.
Just do the same but with a button event, I dont know if you are using click detector or UIs but basically they both have a event for clicks, then all you need to do is put a function to listen to that event where it will check if the player already got a trail and if the player doesn’t have it then you can just put the trail on them.
I used this code and it didn’t work:
local PlayerTrail = game.ReplicatedStorage.Trail
local char = game:GetService("StarterPlayer")
script.Parent.MouseButton1Click:Connect(function()
local TrailClone = PlayerTrail:Clone()
TrailClone.Parent = char.HumanoidRootPart
local attachment1 = Instance.new("Attachment",char.HumanoidRootPart)
attachment1.Name = "TrailAttachment1"
TrailClone.Attachment1 = attachment1
if error then
warn(error)
end
end)
You forgot to add the attachment0, which should be a attachment on humanoid root part.
The attachment1 can be a attachment you can create, parent to humanoid root part, move it by some studs with vector3.
Actually before I had an attachment0 attached to the head but then the output said, Head is not a valid member of StarterPlayer
You must be looking for the player’s head in the wrong service. Replace your line local char = game:GetService("StarterPlayer")
with local char = game:GetService("Players").LocalPlayer.Character
Oh its because of local char = game:GetService(“StarterPlayer”)
Thats not the character, it is an service that contains every thing that should be applied to the player once the player joins.
local Button = script.Parent.TextButton -- Your button
local Trail = game.ReplicatedStorage["Something Trail"] -- Your trail
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait() -- Waiting for character to load
Button.MouseButton1Click:Connect(function() -- When clicked
local CloneTrail = Trail:Clone() -- Cloned trail
CloneTrail.Parent = char:WaitForChild("HumanoidRootPart")
if char:FindFirstChild("UpperTorso") then
CloneTrail.Attachment0 = char.Head.FaceFrontAttachment -- Attachment 0
CloneTrail.Attachment1 = char.UpperTorso.WaistRigAttachment -- Attachment 1
end
end)
Wow! That actually worked! Thanks!