Hello, I am trying to create a remoteevent for updating values on the server side after being changed on the local side. For some reason, it seems to be cloning these events and causing the value to be changed multiple times on the server side, even if its not the desired value. Thanks in advance!
function UpdateVals(itemName, newValue) --update values
values[itemName].Value = newValue
handler:FireServer('UpdateVals', itemName, newValue)
end
lightsMenu.Map.MouseButton1Click:Connect(function() --map lights
local itemName = "Map"
values.CurrentScreen.Value = itemName
values.LastScreen.Value = "LightsMenu"
script.Parent.Ribbon.Back.Visible = true
for i,v in pairs(script.Parent.Content:GetDescendants()) do
if v:IsA("Frame") and v.Name ~= "ToggleMenus" then
v.Visible = false
end
end
selectionOnOff.Visible = true
selectionOnOff.On.MouseButton1Click:Connect(function()
UpdateVals(itemName, "On")
Back("LightsMenu")
end)
selectionOnOff.Off.MouseButton1Click:Connect(function()
UpdateVals(itemName, "Off")
Back("LightsMenu")
end)
end)
function UpdateVals(itemName, newValue) --update values
values[itemName].Value = newValue
handler:FireServer('UpdateVals', itemName, newValue)
end
Server side remote event
wait(.5)
F = {}
local player = nil
local carVals = script.Parent.Parent.Values
F.UpdateVals = function(itemName, newValue)
print (itemName, newValue)
if itemName == "Work" then
if newValue == "On" then
carVals.Lights.WorkLight.Value = true
elseif newValue == "Off" then
carVals.Lights.WorkLight.Value = false
end
elseif itemName == "Map" then
if newValue == "On" then
carVals.Lights.Map.Value = true
elseif newValue == "Off" then
carVals.Lights.Map.Value = false
end
end
print ("---------------------------------------------------------")
end
script.Parent.OnServerEvent:connect(function(pl,Fnc,...)
player = pl
F[Fnc](...)
end)