I want to achieve is to make script that deletes a trail on character.
Script :
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local attachment0 = Instance.new("Attachment", char.Head)
local attachment1 = Instance.new("Attachment", char.HumanoidRootPart)
attachment0.Name = "TrailAttach0"
attachment1.Name = "TrailAttach1"
end)
end)
game.ReplicatedStorage.TrailScripts.Equip.RemoteRed.OnServerEvent:Connect(function(player, trail)
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character.Humanoid
-- Deletes other trail on body..
local Trail = character:IsA("Trail")
wait()
if character:IsA("Trail") then
wait()
Trail:Destroy()
-- Makes a trail
local clone = game.ReplicatedStorage.Trails:FindFirstChild("Red Trail"):Clone()
clone.Parent = player.Character
clone.Attachment0 = player.Character.Head.TrailAttach0
clone.Attachment1 = player.Character.HumanoidRootPart.TrailAttach1
end
end)
local Trail = character:IsA("Trail")
wait()
if character:IsA("Trail") then
wait()
Trail:Destroy()
This part doesn’t make sense and it’s probably the thing stopping the event from working. The function :IsA("Trail") is used to check if something is of the class “Trail”, but obviously your character can’t be a trail. You have to check for trails INSIDE the character, and not check if the character itself is a trail.
game.ReplicatedStorage.TrailScripts.Equip.RemoteRed.OnServerEvent:Connect(function(player, trail)
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character.Humanoid
-- Deletes other trail on body..
repeat
wait()
character:FindFirstChildWhichIsA("Trail", true):Destroy()
until character:FindFirstChildWhichIsA("Trail", true) == nil
-- Makes a trail
local clone = game.ReplicatedStorage.Trails:FindFirstChild("Red Trail"):Clone()
clone.Parent = player.Character
clone.Attachment0 = player.Character.Head.TrailAttach0
clone.Attachment1 = player.Character.HumanoidRootPart.TrailAttach1
end)