(Solved) I need help changing the color of the trail if someone owns a gamepass

local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local GAMEPASS_ID = 846527731
local MarketplaceService = game:GetService("MarketplaceService")

local function createGreenCylinder()
	local cylinder = Instance.new("Part")
    cylinder.Size = Vector3.new(1.1, 0.1, 1)
    cylinder.Anchored = true
	cylinder.CanCollide = false
	cylinder.Transparency = 0.9
		cylinder.Color = Color3.fromRGB(71, 246, 255) -- if has gamepass be this color
		cylinder.Color = Color3.fromRGB(67, 208, 67) -- if DOESN'T have gamepass be this color	


local function spawnTrail(player)
    local character = player.Character or player.CharacterAdded:Wait()
    local humanoidRootPart = character:FindFirstChild("UpperTorso")
    
    if humanoidRootPart then
        while character.Parent do
            local cylinder = createGreenCylinder()
			local currentCFrame = humanoidRootPart.CFrame
			local funny = currentCFrame.Position
			local trailPosition = Vector3.new(funny.X, funny.Y - 0.65, funny.Z)
			cylinder.CFrame = CFrame.new(trailPosition)
            cylinder.Parent = Workspace.PlayerPaths

            -- Gradually fade and remove the cylinder
            task.spawn(function()
                for i = 90, 100 do
                    cylinder.Transparency = i / 100
                    task.wait(0.2)
                end
                cylinder:Destroy()
            end)

            task.wait(0.01)
        end
    end
end

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function()
        spawnTrail(player)
    end)
end)

for _, player in Players:GetPlayers() do
		player.CharacterAdded:Connect(function()
			spawnTrail(player)
		end)
	end
end


Please help!
note the parts aren’t actually cylinders, they were at one point but i was too lazy to change the name

first of all i need to know if this is from a local script or a server script. (assuming its a server script rn)

local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local GAMEPASS_ID = 846527731
local MarketplaceService = game:GetService("MarketplaceService")

local function createGreenCylinder(player)
	local cylinder = Instance.new("Part")
	cylinder.Size = Vector3.new(1.1, 0.1, 1)
	cylinder.Anchored = true
	cylinder.CanCollide = false
	cylinder.Transparency = 0.9
	if MarketplaceService:UserOwnsGamePassAsync(player.UserId, GAMEPASS_ID) then
	cylinder.Color = Color3.fromRGB(71, 246, 255) -- if has gamepass be this color
	else
	cylinder.Color = Color3.fromRGB(67, 208, 67) -- if DOESN'T have gamepass be this color
	end	


	local function spawnTrail(player)
		local character = player.Character or player.CharacterAdded:Wait()
		local humanoidRootPart = character:FindFirstChild("UpperTorso")

		if humanoidRootPart then
			while character.Parent do
				local cylinder = createGreenCylinder(player)
				local currentCFrame = humanoidRootPart.CFrame
				local funny = currentCFrame.Position
				local trailPosition = Vector3.new(funny.X, funny.Y - 0.65, funny.Z)
				cylinder.CFrame = CFrame.new(trailPosition)
				cylinder.Parent = Workspace.PlayerPaths

				-- Gradually fade and remove the cylinder
				task.spawn(function()
					for i = 90, 100 do
						cylinder.Transparency = i / 100
						task.wait(0.2)
					end
					cylinder:Destroy()
				end)

				task.wait(0.01)
			end
		end
	end

	game.Players.PlayerAdded:Connect(function(player)
		player.CharacterAdded:Connect(function()
			spawnTrail(player)
		end)
	end)

	for _, player in Players:GetPlayers() do
		player.CharacterAdded:Connect(function()
			spawnTrail(player)
		end)
	end
end

let me know if this doesnt work

It’s not spawning the trail anymore and yes it is a server script. Sorry I didn’t respond earlier I was sleeping

maybe this?

local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local GAMEPASS_ID = 846527731
local MarketplaceService = game:GetService("MarketplaceService")

local function createGreenCylinder()
	local cylinder = Instance.new("Part")
	for i, v in pairs(Players:GetChildren()) do
		if MarketplaceService:UserOwnsGamePassAsync(v.UserId, GAMEPASS_ID) then
			cylinder.Color = Color3.fromRGB(71, 246, 255) -- if has gamepass be this color
		else
			cylinder.Color = Color3.fromRGB(67, 208, 67) -- if DOESN'T have gamepass be this color
		end	
	end
	cylinder.Size = Vector3.new(1.1, 0.1, 1)
	cylinder.Anchored = true
	cylinder.CanCollide = false
	cylinder.Transparency = 0.9


	local function spawnTrail(player)
		local character = player.Character or player.CharacterAdded:Wait()
		local humanoidRootPart = character:FindFirstChild("UpperTorso")

		if humanoidRootPart then
			while character.Parent do
				local cylinder = createGreenCylinder()
				local currentCFrame = humanoidRootPart.CFrame
				local funny = currentCFrame.Position
				local trailPosition = Vector3.new(funny.X, funny.Y - 0.65, funny.Z)
				cylinder.CFrame = CFrame.new(trailPosition)
				cylinder.Parent = Workspace.PlayerPaths

				-- Gradually fade and remove the cylinder
				task.spawn(function()
					for i = 90, 100 do
						cylinder.Transparency = i / 100
						task.wait(0.2)
					end
					cylinder:Destroy()
				end)

				task.wait(0.01)
			end
		end
	end

	game.Players.PlayerAdded:Connect(function(player)
		player.CharacterAdded:Connect(function()
			spawnTrail(player)
		end)
	end)

	for _, player in Players:GetPlayers() do
		player.CharacterAdded:Connect(function()
			spawnTrail(player)
		end)
	end
end

Still nothin, would it help to know it’s in serverscriptservices?

Server scripts are meant to be in server script service, that part is ok

do you know why it might not be working?

I edited that script and got it working

local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local MarketplaceService = game:GetService("MarketplaceService")

local GAMEPASS_ID = 846527731 

local function createGreenCylinder(player)
	local cylinder = Instance.new("Part")
	if MarketplaceService:UserOwnsGamePassAsync(player.UserId, GAMEPASS_ID) then
		cylinder.Color = Color3.fromRGB(71, 246, 255) -- if has gamepass be this color
	else
		cylinder.Color = Color3.fromRGB(67, 208, 67) -- if DOESN'T have gamepass be this color
	end    
	cylinder.Size = Vector3.new(1.1, 0.1, 1)
	cylinder.Anchored = true
	cylinder.CanCollide = false
	cylinder.Transparency = 0.9
	return cylinder
end

local function spawnTrail(player)
	local character = player.Character or player.CharacterAdded:Wait()
	local humanoidRootPart = character:FindFirstChild("UpperTorso")

	if humanoidRootPart then
		while character.Parent do
			local cylinder = createGreenCylinder(player)
			local currentCFrame = humanoidRootPart.CFrame
			local funny = currentCFrame.Position
			local trailPosition = Vector3.new(funny.X, funny.Y - 0.65, funny.Z)
			cylinder.CFrame = CFrame.new(trailPosition)

			if not Workspace:FindFirstChild("PlayerPaths") then
				local playerPathsFolder = Instance.new("Folder")
				playerPathsFolder.Name = "PlayerPaths"
				playerPathsFolder.Parent = Workspace
			end

			cylinder.Parent = Workspace.PlayerPaths

			task.spawn(function()
				for i = 90, 100 do
					cylinder.Transparency = i / 100
					task.wait(0.2)
				end
				cylinder:Destroy()
			end)

			task.wait(0.01)
		end
	end
end

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		spawnTrail(player)
	end)
end)

for _, player in Players:GetPlayers() do
	player.CharacterAdded:Connect(function()
		spawnTrail(player)
	end)
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.