local Players = game:GetService("Players") local audio = game.ServerStorage.Items.Effects.Audio.Sound local particle1 = game.ServerStorage.Items.Effects.Particles.ParticleEmitter local particle2 = game.ServerStorage.Items.Effects.Particles.ParticleEmitter2 local velocity = game.ServerStorage.Items.Effects.Velocity.BodyVelocity function onPlayerAdded(player) audio:Clone() audio.Parent = game.Players end Players.PlayerAdded:connect(onPlayerAdded) for _,player in pairs(Players:GetPlayers()) do onPlayerAdded(player) end
What I want it to do is to move different classes/instances from lighting or serverstorage to a player when they join/re spawn but they don't seem to work.
Instead of storing the cloned audio in a variable, you don't. If you don't use this, you can't reference the cloned object
You are using :connect()
. This is deprecated or not recommended to use. Use :Connect()
You are looping the players even though you have made the onPlayerAdded()
to listen for the PlayerAdded event.
The PlayerAdded event already has its own argument, the player, so, you don't need to call the function again. Even though the player resets, it will still work.
Here is the fix:
--\\ Services local Players = game:GetService("Players") local serverStorage = game:GetService("ServerStorage") --\\ Cloned Objects local items = serverStorage:WaitForChild("Items") local effects = items:WaitForChild("Effects") local sounds = effects:WaitForChild("Audio") local audio = audio:WaitForChild("Sound") local particles = effects:WaitForChild("Particles") local particle1 = particles:WaitForChild("ParticleEmitter") local particle2 = particles:WaitForChild("ParticleEmitter2") local velocityFolder = effects:WaitForChild("Velocity") local velocity = velocityFolder:WaitForChild("BodyVelocity") --\\ Clone Sound onPlayerAdded() function onPlayerAdded(player) local newAudio = audio:Clone() newAudio.Parent = Players end Players.PlayerAdded:Connect(onPlayerAdded)