Finding an item in every players inventory and changing it

Hi! I am trying to replicate live light wristbands that flash and change colours like in real life concerts, in the crowd.

I am instead, using a ‘glowstick’.

The part I need help with is referencing the glowstick in every players inventory to apply effects to each glowstick. Note that it is optional, so players can choose if they want one or not. If the script does not find a glowstick in someones inventory, it moves on to the next player.

How would I go about this?

Use RemoteEvents. It has a function called :FireAllClients() which basically fires the event to every single player. If one doesn’t have a glowstick, it won’t affect anything. Plus, this happens with every player at the same time.
The glowstick can be scripted so that whenever the RemoteEvent is fired, it will apply effects itself.

1 Like

wont that mean that the glowstick effects are client sided? Like when the server script fires to each client, will that mean that each player will only see their glowstick change?

So what you can do for example is create a Color3Value in the workspace perhaps and then make a script to control how you want to change the color of that value. In a local script parented to the tool, once a player equip the glowstick you can simply use the .equipped event and connect that to a function that fires an event to the server passing the tool and the player as arguments. On the server respond to that event by matching the color of the glowstick to that of the color value. I did not test that if it works or not but just throwing a solution idea to try.
EDIT: you will also need to do an .Changed event for the color value and then do a for loop over the players’ characters and check if they have the glowstick in their character or not an if they did match the color again. So it keeps updated all the time.

1 Like

Depends if the effect can replicate to both server and client. What kind of effects are you trying to do?

By “Inventory”, do you mean the Roblox backpack, or a different, custom inventory?

If the glow stick is part of the character model, you can change the color with a pretty simple server-side script. It would look something like this:

local players = game:GetService("Players")

function setGlowsticks(color)
    for _,v in pairs(players:GetChildren()) do               -- Cycle through all players in the game
        local glow = v.Character:FindFirstChild("Glowstick") -- Search for a glowstick in each player's character
        if glow then                                         -- If we find one...
            glow.BrickColor = color                          -- set its color.
        end
    end
end

Then you’d probably use a for loop or similar to cycle through colors.

If you are using the default inventory then you can use a for loop

local Players = game:GetService("Players")

function AddEffects(GlowStick)
--//   Whatever You Want   \\--
end

for _ , v in pairs(Players:GetDescendants()) do 
if v:IsA("Tool") and v.Name == "glowstick" then
AddEffects(v)
end
end