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

Player event is triggering to all Players?

Asked by
Aozwel 71
4 years ago
Edited 4 years ago

Hi there, i’m pretty new to scripting and the mistake might be obvious but i’m unsure on what i need to change fix this,

The issue is bascailly when a Player clicks the Values/ “Equipped” text changes for all Players instead of the local player.

Local Script:

01local player = game:GetService(“Players”).LocalPlayer
02local RS = game:GetService(“ReplicatedStorage”)
03local gui = script.Parent
04– Items
05local function UpdateKillEffect()
06local Killeffects = player:WaitForChild(“KillEffects”)
07 
08for i, Button in pairs(gui.KillEffectScroll:GetChildren()) do
09if Button:IsA(“ImageButton”) then
10if Killeffects:FindFirstChild(Button.Name) then
11Button.EquipStatus.Text = “Owned”
12end
13if player.EquippedKillEffect.Value == Button.Name then
14Button.EquipStatus.Text = “Equipped”
15end
View all 47 lines...

Server Script:

01local RS = game:GetService(‘ReplicatedStorage’)
02game:GetService(“Players”).PlayerAdded:Connect(function(Player)
03 
04local currentcoins = Player:WaitForChild(“coinstats”).Coins
05local storage = RS.KillEffects
06 
07local EquippedKillEffect = Instance.new(“StringValue”)
08EquippedKillEffect.Parent = Player
09EquippedKillEffect.Name = “EquippedKillEffect”
10EquippedKillEffect.Value = “None”
11 
12RS.Remotes.EquippedKillEffect.OnServerEvent:Connect(function(player, Type, Name, Price) print(“Fired Server”)
13if not Name then return end
14if not Type then return end
15if type(Name) ~= ‘string’ then return end
View all 35 lines...

Thanks,

1 answer

Log in to vote
1
Answered by
sayer80 457 Moderation Voter
4 years ago
  1. game:GetService(“Players”).PlayerAdded:Connect(function(Player) When there are 5 Players then the function will run 5 Times and each player will have a changed thing, as every function will be assigned to each player. You should just remove the function and define equipedkilleffect and that stuff inside the .OnServerEvent and you should get the equippedkilleffect with waitforchild then
01local RS = game:GetService(‘ReplicatedStorage’)
02local storage = RS.KillEffects
03 
04game:GetService(“Players”).PlayerAdded:Connect(function(Player)
05local EquippedKillEffect = Instance.new(“StringValue”)
06EquippedKillEffect.Parent = Player
07EquippedKillEffect.Name = “EquippedKillEffect”
08EquippedKillEffect.Value = “None”
09end)
10 
11RS.Remotes.EquippedKillEffect.OnServerEvent:Connect(function(player, Type, Name, Price) print(“Fired Server”)
12local currentcoins = Player:WaitForChild(“coinstats”).Coins
13local EquippedKillEffect = Player:WaitForChild(“EquippedKillEffect”)
14if not Name then return end
15if not Type then return end
View all 35 lines...
Ad

Answer this question