when a player in my game clicks a button in a menu in my game it sets a string value on the player to the equipped value of the button i named the value eq like if the player equips the color blue the value will be set to Blue. however its in a local script and only sets it client side. but if i change it to a regular script it dosent work at all and my game script reads the players eq value on the server side to give them the blue weapon.
Script on button:
local player = game.Players.LocalPlayer script.Parent.MouseButton1Click:Connect(function() if player.Shop.Red.Value == true then player.eq.Value = "Red" end end)
Code in game script:
for _, player in pairs (game.Players:GetPlayers()) do if player.eq.Value == "Red" then local primary = game.ReplicatedStorage.Red local newprimary = primary:Clone() newprimary.Parent = player.Backpack end if player.eq.Value == "Yellow" then local primary = game.ReplicatedStorage.Yellow local newprimary = primary:Clone() newprimary.Parent = player.Backpack end if player.eq.Value == "Blue" then local primary = game.ReplicatedStorage.Blue local newprimary = primary:Clone() newprimary.Parent = player.Backpack end if player.eq.Value == "Green" then local primary = game.ReplicatedStorage.Green local newprimary = primary:Clone() newprimary.Parent = player.Backpack end if player.eq.Value == "None" then local primary = game.ReplicatedStorage.Sword local newprimary = primary:Clone() newprimary.Parent = player.Backpack end end
Step 1: Create remote event named changeEq(or whatever name you want, just change the script) in Replicated Storage. Step 2: Create a local script to signal the event to fire Step 3: Create the server script to run when the event is fired
Local Script
local player = game.Players.LocalPlayer script.Parent.MouseButton1Click:Connect(function() if player.Shop.Red.Value == true then local color = "Red" game.ReplicatedStorage.changeEq:FireServer(color) end end)
Server Script
game.ReplicatedStorage.changeEq.OnServerEvent:Connect(function(player, color) player.eq.Value = color end)