So I decided to make this Trail Script for VIP users in a game I’ve been working on for a long time now. I was wondering if I could make this code more efficient so it’s not such a big long script. I know this prob doesn’t look the best but It works for me. Explaining what it does, so if I was to do the command “!trail white” in chat it would give me a trail and if I did “!untrail” it would remove the trail. if there is nothing else that can be done its fine. I just think it was all kind of a mess lol
local Command1 = "!trail white"
local Command2 = "!trail red"
local Command3 = "!trail blue"
local Command4 = "!trail purple"
local Command5 = "!trail pink"
local Command6 = "!trail black"
local Command7 = "!trail green"
local Command8 = "!trail yellow"
local UnCommand = "!untrail"
local MarketPlaceService = game:GetService("MarketplaceService")
local gamepass = 1 --[[Just had to remove it]]--
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(chr)
player.Chatted:Connect(function(msg)
local PlayerBoughtThisGamePass = MarketPlaceService:UserOwnsGamePassAsync(player.UserId, gamepass)
local trail = player.Character:FindFirstChild('Trail')
local newTrail = Instance.new('Trail')
if PlayerBoughtThisGamePass then
if msg == Command1 then
pcall(function()
if player.Character:FindFirstChild('Trail') then
trail.Color = ColorSequence.new(Color3.fromRGB(255, 255, 255), Color3.fromRGB(255, 255, 255))
else
newTrail.Parent = player.Character
newTrail.Attachment0 = player.Character.HumanoidRootPart.RootRigAttachment
newTrail.Attachment1 = player.Character.Head.NeckRigAttachment
newTrail.Color = ColorSequence.new(Color3.fromRGB(255, 255, 255), Color3.fromRGB(255, 255, 255))
end
end)
end
if msg == Command2 then
pcall(function()
if player.Character:FindFirstChild('Trail') then
trail.Color = ColorSequence.new(Color3.fromRGB(255, 0, 0), Color3.fromRGB(255, 0, 0))
else
newTrail.Parent = player.Character
newTrail.Attachment0 = player.Character.HumanoidRootPart.RootRigAttachment
newTrail.Attachment1 = player.Character.Head.NeckRigAttachment
newTrail.Color = ColorSequence.new(Color3.fromRGB(255, 0, 0), Color3.fromRGB(255, 0, 0))
end
end)
end
if msg == Command3 then
pcall(function()
if player.Character:FindFirstChild('Trail') then
trail.Color = ColorSequence.new(Color3.fromRGB(0, 170, 255), Color3.fromRGB(0, 170, 255))
else
newTrail.Parent = player.Character
newTrail.Attachment0 = player.Character.HumanoidRootPart.RootRigAttachment
newTrail.Attachment1 = player.Character.Head.NeckRigAttachment
newTrail.Color = ColorSequence.new(Color3.fromRGB(0, 170, 255), Color3.fromRGB(0, 170, 255))
end
end)
end
if msg == Command4 then
pcall(function()
if player.Character:FindFirstChild('Trail') then
trail.Color = ColorSequence.new(Color3.fromRGB(0, 0, 127), Color3.fromRGB(0, 0, 127))
else
newTrail.Parent = player.Character
newTrail.Attachment0 = player.Character.HumanoidRootPart.RootRigAttachment
newTrail.Attachment1 = player.Character.Head.NeckRigAttachment
newTrail.Color = ColorSequence.new(Color3.fromRGB(0, 0, 127), Color3.fromRGB(0, 0, 127))
end
end)
end
if msg == Command5 then
pcall(function()
if player.Character:FindFirstChild('Trail') then
trail.Color = ColorSequence.new(Color3.fromRGB(170, 85, 127), Color3.fromRGB(170, 85, 127))
else
newTrail.Parent = player.Character
newTrail.Attachment0 = player.Character.HumanoidRootPart.RootRigAttachment
newTrail.Attachment1 = player.Character.Head.NeckRigAttachment
newTrail.Color = ColorSequence.new(Color3.fromRGB(170, 85, 127), Color3.fromRGB(170, 85, 127))
end
end)
end
if msg == Command6 then
pcall(function()
if player.Character:FindFirstChild('Trail') then
trail.Color = ColorSequence.new(Color3.fromRGB(0, 0, 0), Color3.fromRGB(0, 0, 0))
else
newTrail.Parent = player.Character
newTrail.Attachment0 = player.Character.HumanoidRootPart.RootRigAttachment
newTrail.Attachment1 = player.Character.Head.NeckRigAttachment
newTrail.Color = ColorSequence.new(Color3.fromRGB(0, 0, 0), Color3.fromRGB(0, 0, 0))
end
end)
end
if msg == Command7 then
pcall(function()
if player.Character:FindFirstChild('Trail') then
trail.Color = ColorSequence.new(Color3.fromRGB(0, 255, 0), Color3.fromRGB(0, 255, 0))
else
newTrail.Parent = player.Character
newTrail.Attachment0 = player.Character.HumanoidRootPart.RootRigAttachment
newTrail.Attachment1 = player.Character.Head.NeckRigAttachment
newTrail.Color = ColorSequence.new(Color3.fromRGB(0, 255, 0), Color3.fromRGB(0, 255, 0))
end
end)
end
if msg == Command8 then
pcall(function()
if player.Character:FindFirstChild('Trail') then
trail.Color = ColorSequence.new(Color3.fromRGB(255, 255, 0), Color3.fromRGB(255, 255, 0))
else
newTrail.Parent = player.Character
newTrail.Attachment0 = player.Character.HumanoidRootPart.RootRigAttachment
newTrail.Attachment1 = player.Character.Head.NeckRigAttachment
newTrail.Color = ColorSequence.new(Color3.fromRGB(255, 255, 0), Color3.fromRGB(255, 255, 0))
end
end)
end
if msg == UnCommand then
pcall(function()
player.Character:FindFirstChild('Trail'):Destroy()
end)
end
end
end)
end)
end)