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

How to add different accessories to players depending on the selected map?

Asked by 2 years ago
Edited 2 years ago

So I have a place in which you need to combine balls of the same color and size (the default fanmade on "Merge!"). At one point, I wanted ALL the players to have all sorts of accessories corresponding to the theme of the map (For example, the selected map is Winter, so the players should have a hat and scarf).

All my hats that I prepare for the map are in the ServerStorage.Clothing.THEME

However, everything was going pretty well - I myself wrote a simple script that was responsible for adding accessories. But when I was playing with my brother, I noticed that accessories are added only to one of all the players on the server. I'm not a professional scriptwriter, so I can't solve this problem, and I'm asking someone to help and tell me what to do and, if possible, improve or simplify my script!

I also say that the script is in a huge invisible anchored block covering the entire map, which appears along with the map itself and which the players is touching to get accessories. ALSO I'm testing my place using Roblox Studio's "Play"

Here is the script (dressing accessories with dice theme):

local model = script.Parent

local debounce = false 
model.Touched:Connect(function(part)
    if part.Parent:FindFirstChildOfClass("Humanoid") then

        if debounce then return end 

        debounce = true         

        wearFallingDice = game.ServerStorage.Clothing.Dice.FallingDice:Clone()
        wearDiceHat = game.ServerStorage.Clothing.Dice.Ff:Clone()
        wearFallingDice.Parent = part.Parent
        wearDiceHat.Parent = part.Parent

        wait(14)

        wearFallingDice:Destroy()
        wearDiceHat:Destroy()

    end
end)

I added debounce(which I was looking in Internet for to solve the following problem in this sentence) in the script because when I tested this script, I had hundreds of selected accessories in my character.

The accessories removes after 14 seconds, because I put a 15-second map change to test maps and script's work.

Also It is a script, not LocalScript or ModuleScript.

A clear example of my problem : https://docs.google.com/document/d/12zjdfb0ZxwC1k6Rtq4xzGd1NGOiSWfOtNFFFli7iAQE/edit?usp=sharing

(Here my brother and I show what I meant by the above)

I would be very happy if I solved this problem, because without this little addition, my game will be more boring and similar to the original (the original is not boring at all!!!).

1 answer

Log in to vote
0
Answered by
Puppynniko 1059 Moderation Voter
2 years ago
Edited 2 years ago

i wrote this script that can help with adding it to all players

local Players = game:GetService("Players")

function AllPlayersWearAccessory(Accessory)
    for i,v in pairs(Players:GetPlayers()) do
        if Accessory:IsA("Accessory") then
            local ClonedAccessory = Accessory:Clone()
            v.Character:WaitForChild("Humanoid"):AddAccessory(ClonedAccessory)
        end
    end
end

wait(20)
AllPlayersWearAccessory(game.ServerStorage["Fast Food Worker"])
0
Thanks, It's worked IgromanEXE 9 — 1y
Ad

Answer this question