Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
ghxstlvty 133
4 years ago

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

Log in to vote
1
Answered by 4 years ago
-- 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)
0
Works, thank you so much! ghxstlvty 133 — 4y
0
no problem! FunctionalMetatable 490 — 4y
Ad
Log in to vote
0
Answered by
raid6n 2196 Moderation Voter Community Moderator
4 years ago

Try cloning the trail and moving its parent.

0
^ to explain more, clone the trail in CharacterAdded zadobyte 692 — 4y
0
mhm raid6n 2196 — 4y
0
The trail is cloning in CharacterAdded. The variable has :Clone at the end and is under CharacterAdded. ghxstlvty 133 — 4y

Answer this question