Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Rainbow Trail Gamepass only works on one player at a time. Any help?

Server Script in ServerScriptService:

local ServerStorage = game.ServerStorage.RainbowTrail:Clone()
local gamepassid = 10498381

local function hasGP(pid, gpid)
	return game:GetService("MarketplaceService"):UserOwnsGamePassAsync(pid, gpid)
end

local function attach(child, attachments)
	for i = 1,#attachments do
		local offset = tostring(i -1)
		local attachment = Instance.new("Attachment")
		attachment.Parent = attachments[i]
		attachment.Name = "TrailAttachment"..offset
		child["Attachment"..offset] = attachment
	end
	child.Parent = attachments[1]
end

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(chr)
		if hasGP(plr.UserId, gamepassid) then
			attach(ServerStorage, {chr.Head, chr.HumanoidRootPart})
		end
	end)
end)

For some reason the trail only works on 1 player at a time. Ex: I had the trail, my friend joined, my trail got deleted and the trail went to him.

2 answers

✓ Accepted answer
-- took me 5 mins lol
local gamePassId = 10498381
local RainbowTrail = game.ServerStorage.RainbowTrail
local function UserOwnsGamePassAsync(player, gamePassId)
	local hasGamepass = false
	local MarketplaceSuccess, MarketplaceErr = pcall(function() -- Wrap in a pcall because errors can come up.
		hasGamepass = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, gamePassId)
	end)
	if MarketplaceSuccess then
		return hasGamepass
	else
		warn("Error on MarketplaceService:UserOwnsGamePassAsync: ", MarketplaceErr)
		return false
	end
end
local function attach(ch, att)
	for i = 1, #att do
		local off = tostring(i-1)
		local attachment = Instance.new("Attachment")
		attachment.Parent = att[i]
		attachment.Name = "TrailAttachment-"..off
		ch["Attachment"..off] = attachment
	end
	ch.Parent = att[1]
end
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		if UserOwnsGamePassAsync(plr, gamePassId) then
			attach(RainbowTrail:Clone(), {char.Head, char.HumanoidRootPart})
		end
	end)
end)

2 comments

0

Works, thank you so much!

0

no problem!

Try cloning the trail and moving its parent.

3 comments

0

^ to explain more, clone the trail in CharacterAdded

0

mhm

0

The trail is cloning in CharacterAdded. The variable has :Clone at the end and is under CharacterAdded.

This discussion is preserved as it was. New answers, comments, and votes are closed.