Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Unable to detect a Value inside the player within a workspace script?

This script is in a coin that once you touch it, it is supposed to give you a certain amount of coins, then destroy itself, which it does (mostly) correctly. But the problem is that when I tried to introduce a modifier to how much coins it gives me. It still adds to coins like it should, but when the game open the modifier starts at 1, and when I press a button it changes to 2. But the script isn't changing the "coinage" value to 2 also, it just stays at 1, I'm sorry if my explanation is a bit unclear, if you need clarification just ask me. Could someone explain why this doesn't work, and point me in the right direction? thanks in advance Here's my script:

script.Parent.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") ~= nil then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		local value = player.leaderstats.coins.Value
		local coinage = player.leaderstats.coinage12.Value
		local num = math.random(1,2)
		local luckynum = math.random(1,10)
		if luckynum == 1 then
			num = num + 1
		end
		local num1 = num * coinage
		value = value + num1
		script.Parent:Destroy()
	end
end)

1 answer

✓ Accepted answer

That is because you are storing their values in a variable and then you're just changing that variable, not the actual value.

So instead of

local value = player.leaderstats.coins.Value
local coinage = player.leaderstats.coinage12.Value

Do

local value = player.leaderstats.coins
local coinage = player.leaderstats.coinage12

Also change these to the num1 and value assignment to

local num1 = num * coinage.Value
value.Value = value.Value + num1

Hope this helps, if you have any questions please let me know!

This discussion is preserved as it was. New answers, comments, and votes are closed.