Hi, I am trying to make a script that gives players a trail if they have premium but if the player does not have premium the trail color will change to white. The trail works for the premium player but the trail doesn’t even show for the non-premium player. I checked the output and script analysis and it did not drop anything.
local ReplicatedStorage = game.ServerStorage
local white = Color3.new(1,1,1)
local Trail = ReplicatedService.Trail:Clone()
local players = game.Players
players.PlayerAdded:Connect(function(player)
player.CharacterAppearanceLoaded:Connect(function(char)
if player.MembershipType == Enum.MembershipType.Premium then
Trail.Parent = char.Head
local attachment0 = Instance.new("Attachment", char.Head)
attachment0.Name = "attachment0"
local attachment1 = Instance.new("Attachment", char.HumanoidRootPart)
attachment1.Name = "attachment1"
Trail.Attachment0 = attachment0
Trail.Attachment1 = attachment1
if player.MembershipType ~= Enum.MembershipType.Premium then
Trail.Color = ColorSequence.new{
ColorSequenceKeypoint.new(0, white)
}
end
end
end)
end)
The trail is given to the non-premium player but it does not change its color
It drops an error in the output: ServerScriptService.Script:18: invalid argument #1 to ‘new’ (number expected, got Color3) - Server - Script:18
on this line: ColorSequenceKeypoint.new(Color3.new(1,1,1))
So first off, the trail must be paranted to the HumanoidRootPart, not the head.
And you’ll need to check and see if the player already has all the necessary attachments before attaching the trail.
Here’s a script I’ve written for you that I’ve tested and should work.
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local white = Color3.new(1,1,1)
local function CheckAttachments(character) -- Check to see if the player's character has the necessary attachments
if not character.Head:FindFirstChild("FaceFrontAttachment") then
local Attachment = Instance.new("Attachment")
Attachment.Name = "FaceFrontAttachment"
Attachment.Position = Vector3.new(0, 0, -0.6)
Attachment.Parent = character.Head
end
if character:FindFirstChild("UpperTorso") then
if not character.UpperTorso:FindFirstChild("WaistRigAttachment") then
local Attachment = Instance.new("Attachment")
Attachment.Name = "WaistRigAttachment"
Attachment.Position = Vector3.new(-0.8, 0, 0)
Attachment.Parent = character.UpperTorso
end
else
if not character.Torso:FindFirstChild("WaistRigAttachment") then
local Attachment = Instance.new("Attachment")
Attachment.Name = "WaistRigAttachment"
Attachment.Position = Vector3.new(0, -0.75, 0)
Attachment.Parent = character.Torso
end
end
end
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local trail = ServerStorage.Trail:Clone()
trail.Parent = character.HumanoidRootPart
CheckAttachments(character)
if character:FindFirstChild("UpperTorso") then
trail.Attachment0 = character.Head.FaceFrontAttachment
trail.Attachment1 = character.UpperTorso.WaistRigAttachment
else
trail.Attachment0 = character.Head.FaceFrontAttachment
trail.Attachment1 = character.Torso.WaistBackAttachment
end
if player.MembershipType == Enum.MembershipType.Premium then
trail.Color = ColorSequence.new(white)
end
end)
end)
and I’m not sure why it worked like this but I Changed it to
if player.MembershipType == Enum.MembershipType.None then
trail.Color = ColorSequence.new(white)
Final code
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local white = Color3.new(1,1,1)
local function CheckAttachments(character) -- Check to see if the player's character has the necessary attachments
if not character.Head:FindFirstChild("FaceFrontAttachment") then
local Attachment = Instance.new("Attachment")
Attachment.Name = "FaceFrontAttachment"
Attachment.Position = Vector3.new(0, 0, -0.6)
Attachment.Parent = character.Head
end
if character:FindFirstChild("UpperTorso") then
if not character.UpperTorso:FindFirstChild("WaistRigAttachment") then
local Attachment = Instance.new("Attachment")
Attachment.Name = "WaistRigAttachment"
Attachment.Position = Vector3.new(-0.8, 0, 0)
Attachment.Parent = character.UpperTorso
end
else
if not character.Torso:FindFirstChild("WaistRigAttachment") then
local Attachment = Instance.new("Attachment")
Attachment.Name = "WaistRigAttachment"
Attachment.Position = Vector3.new(0, -0.75, 0)
Attachment.Parent = character.Torso
end
end
end
Players.PlayerAdded:Connect(function(player)
player.CharacterAppearanceLoaded:Connect(function(character)
local trail = ServerStorage.Trail:Clone()
trail.Parent = character.HumanoidRootPart
CheckAttachments(character)
if character:FindFirstChild("UpperTorso") then
trail.Attachment0 = character.Head.FaceFrontAttachment
trail.Attachment1 = character.UpperTorso.WaistRigAttachment
else
trail.Attachment0 = character.Head.FaceFrontAttachment
trail.Attachment1 = character.Torso.WaistBackAttachment
end
if player.MembershipType == Enum.MembershipType.None then
trail.Color = ColorSequence.new(white)
end
end)
end)