Hi so I am making it so that when the local script in startergui fires the server using a remote event, the server script in serverscriptservice picks it up and changes the value which the script is parented in.
it prints everything with no errors but the value is not changing!
please help thank you idk what is going wrong!
--local script firing the server
local coinReceiver = game.ReplicatedStorage:WaitForChild("CoinEvent")
print('set localers')
coinReceiver.OnClientEvent:Connect(function(coinValue)
print('received')
local coinText = script.Parent.Text
local coinVal = tonumber(coinText)
coinText = tostring(coinVal + coinValue)
script.Parent.Text = coinText -- Add this line to update the GUI element with the new coin value
game.ReplicatedStorage.CoinValue:FireServer(coinText)
print('set coins')
end)
--server script picking it up
local val = script.Parent.Value
game.ReplicatedStorage.CoinValue.OnServerEvent:Connect(function(plr, value)
print('received coinvalue event')
local coinString = tonumber(value)
print('made it a number')
val = coinString
print('changed the value to coinstring')
end)
If you make a variable of a Property of an instance, it is making a copy. You can read it and write to this variable but it will not set the actual property of the instance.
local val = script.Parent
game.ReplicatedStorage.CoinValue.OnServerEvent:Connect(function(plr, value)
print('received coinvalue event')
local coinString = tonumber(value)
print('made it a number')
val.Value = coinString
print('changed the value to coinstring')
end)
A lot of your tonumber and tostring calls are useless as roblox does this for you. Asside from that, I donβt see what you script is designed to do. It seems quite unsecure and it would be best to just do this entire thing from the server. What are you trying to accomplish?
so basically i have this script in SSS where it detects when the playerβs stage leaderstat is changed and sends a remote event to a local script where it adds the coins. Then that local script sends another remote event to a diff script in SSS which is the same script i provided in my original post.
so basically:
Detect when stage leaderstat gets changed using script in SSS and fire a remote event
Local script in startergui picks it up and adds the coins to a text label
the local script then fires another remote event
another script in SSS picks that up and changes the IntValue based on the coin value the local script provided.
That is a VERY unsecure method to handle it. Instead, use a .Changed event on the client for your leaderstat and update the textlabel accordingly. You can then change the value of your int value on the server whenever you like and the textlabel will update.