Player event is triggering to all Players?
Asked by
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:
01 | local player = game:GetService(“Players”).LocalPlayer |
02 | local RS = game:GetService(“ReplicatedStorage”) |
03 | local gui = script.Parent |
05 | local function UpdateKillEffect() |
06 | local Killeffects = player:WaitForChild(“KillEffects”) |
08 | for i, Button in pairs (gui.KillEffectScroll:GetChildren()) do |
09 | if Button:IsA(“ImageButton”) then |
10 | if Killeffects:FindFirstChild(Button.Name) then |
11 | Button.EquipStatus.Text = “Owned” |
13 | if player.EquippedKillEffect.Value = = Button.Name then |
14 | Button.EquipStatus.Text = “Equipped” |
16 | if not Killeffects:FindFirstChild(Button.Name) then |
17 | Button.EquipStatus.Text = “Buy” |
25 | player:WaitForChild(“EquippedKillEffect”):GetPropertyChangedSignal(“Value”):Connect( function () |
29 | for i, Button in pairs (gui.KillEffectScroll:GetChildren()) do |
30 | if Button:IsA(“ImageButton”) then |
31 | Button.Activated:Connect( function () print (Button.Name) |
32 | RS.Remotes.EquippedKillEffect:FireServer(“KillEffects”, Button.Name,Button.Price) |
37 | RS.Remotes.Equip.OnClientEvent:Connect( function () |
38 | script.Sounds.Equip:Play() |
41 | RS.Remotes.Bought.OnClientEvent:Connect( function () |
42 | script.Sounds.Buy:Play() |
45 | RS.Remotes.Error.OnClientEvent:Connect( function () |
46 | script.Sounds.Error:Play() |
Server Script:
01 | local RS = game:GetService(‘ReplicatedStorage’) |
02 | game:GetService(“Players”).PlayerAdded:Connect( function (Player) |
04 | local currentcoins = Player:WaitForChild(“coinstats”).Coins |
05 | local storage = RS.KillEffects |
07 | local EquippedKillEffect = Instance.new(“StringValue”) |
08 | EquippedKillEffect.Parent = Player |
09 | EquippedKillEffect.Name = “EquippedKillEffect” |
10 | EquippedKillEffect.Value = “None” |
12 | RS.Remotes.EquippedKillEffect.OnServerEvent:Connect( function (player, Type, Name, Price) print (“Fired Server”) |
13 | if not Name then return end |
14 | if not Type then return end |
15 | if type (Name) ~ = ‘string’ then return end |
16 | if Type = = “KillEffects” then |
17 | if player.KillEffects:FindFirstChild(Name) then |
18 | EquippedKillEffect.Value = (Name) |
19 | RS.Remotes.Equip:FireClient(player) |
21 | elseif not Player.KillEffects:FindFirstChild(Name) then |
22 | if currentcoins.Value > = Price.Value then |
23 | currentcoins.Value = currentcoins.Value - Price.Value |
24 | local newkilleffect = Instance.new(“BoolValue”) |
25 | newkilleffect.Name = (Name) |
26 | newkilleffect.Parent = player.KillEffects |
27 | RS.Remotes.Bought:FireClient(player) |
29 | elseif currentcoins.Value < Price.Value then |
30 | RS.Remotes.Error:FireClient(player) |
Thanks,