hello, please help I don’t know why this is happening so basically; I have a local script that detects when a player completes a stage, then it fires a remote event carrying the value (based on their stage number) as an argument. So the server picks it up in SSS and it’s supposed to change the IntValue that it’s parented in but it doesn’t.
It prints everything else and has no errors but it just doesn’t seem to work
Please help I would appreciate it!
--LOCAL SCRIPT THAT FIRES THE REMOTE EVENT TO SERVER
local plr = game.Players.LocalPlayer
local coinText = plr.PlayerGui.CoinSystem.Frame.TextLabel
plr:WaitForChild("leaderstats"):WaitForChild("Stage"):GetPropertyChangedSignal("Value"):Connect(function()
print('player leaderstats changed')
local leaderstats = plr:WaitForChild("leaderstats"):WaitForChild("Stage").Value
local coinEvent = game.ReplicatedStorage:WaitForChild("CoinEvent")
local coinValue = tonumber(coinText.Text)
print(leaderstats)
if leaderstats < 20 and leaderstats > 1 then --in easy
local newCoin = coinValue + 2 --add 2 coins
coinText.Text = tostring(newCoin)
coinEvent:FireServer(2) --fire the server to save
elseif leaderstats < 40 and leaderstats > 20 then --if in casual
local newCoin = coinValue + 4
coinText.Text = tostring(newCoin)
coinEvent:FireServer(4)
elseif leaderstats < 51 and leaderstats > 40 then --if in medium
local newCoin = coinValue + 5
coinText.Text = tostring(newCoin)
coinEvent:FireServer(5)
end
end)
--SERVER SCRIPT THAT PICKS IT UP
game.ReplicatedStorage.CoinEvent.OnServerEvent:Connect(function(plr, value)
print('received coinvalue event')
print(value, plr.Name)
local val = script.Parent.Value
local newVal = val + value
print(newVal.. " new value")
script.Parent.Value = newVal
print('changed')
end)
It prints everything and no errors but it just doesn’t seem to work. Help please.
well, it’s adding the already stored value in the IntValue with the value that the local script fired right now. For example if in the IntValue there is already 2 coins, then the player gets 2 more coins, it changes the intvalue to 4 coins.
(line 4: local newVal = val + value)
so basically newVal is that and the IntValue is changing to intval
It is changing an IntValue. There is another folder that the IntValue is parented in and that folder is parented in a coin saving script, essentially this:
It is not changing any value for the player, but the CoinSaving script depends on the Coins IntValue to save the data.
Try this, if it works I can explain in my best of abilities of why it probably did not work.
print('received coinvalue event')
print(value, plr.Name)
local newVal = script.Parent.Value + value -- Adds old Value to new Value
print(newVal.. " new value")
script.Parent.Value = newVal -- Sets old value to new value
-- Test to see if it changes then reverts back to old, or just not changing in general
if script.Parent.Value == newVal then
print('changed')
else
print('Error')
end
print('received coinvalue event')
print(value, plr.Name)
local newVal = script.Parent.Value + value -- Adds old Value to new Value
print(newVal.. " new value")
script.Parent.Value = newVal -- Sets old value to new value
-- Test to see if it changes then reverts back to old, or just not changing in general
if script.Parent.Value == newVal then
print('changed')
else
print('Error')
end
Are you viewing the change on the Workspace Explorer or on a GUI screen?
everything works but idk what you’re doing to check the Coins value go to Test and click on Current: Client so it changes to Current: Server then you can view the value
You’re checking the wrong place there. That’s not what the script is changing do what i said above then go the the ServerScriptService and find Coins it will have the value you want