Why is the value not changing? [HELP!]

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 :frowning:

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.

In your ServerScriptService, the 3rd from last line is script.Parent.Value, is this trying to be the players coin value or something else?

script.Parent.Value = newVal

I recommend adding comments of where things go or what things do so when you need to ask a question, people can properly read your code.

1 Like

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

Is this meant to change the coin value or what stage the player is on?

Which script? The server script or the local script.

Serverscript, essentially what kind of value is it changing for the player.

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:

image

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

Did not work sadly :frowning:

Summary

character limti

Test this real quick.

	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?

Sorry lol studio is broken for me rn ill get back to u ASAP my friend also having problems with it

If you don’t mind asking this question real quick, are you viewing the change on the Explorer window or on a GUI screen?

what do you mean by that? Are you asking how I check the IntValue in-game?

Yes, are you viewing the value from the Explorer window or are you waiting for a gui screen to update

I am viewing it via explorer window:

Players > MyName > playerstats > Coins

1 Like

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

1 Like

But why does it not change on client version?

Because ServerScriotService isn’t available from the Client

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.