IntValue is Broken

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want IntValue to be normal

  2. What is the issue? When while wait(5) do the generate coin thing, It’s normal, But IntValue is broken when it’s generated

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?, Yes I look for the hub

  • I try printing in almost the end of Generate Script and it’s normal
  1. More Info
  • No script disturbing IntValue
  • IntValue that inserted is a Number
  • I use WaitForCHild on IntValue
  • If you want more info, Feel free to ask me when I am online!

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

A code of Generate Coins script

local coin = script.Parent:WaitForChild("coin")

while wait(5) do
	local chance = math.random(1,10000) / 100
	local clonedCoin = coin:Clone()
	local toReward = clonedCoin:WaitForChild("rewardCoin").Value
	local lobbyFloorSize = workspace:WaitForChild("lobbyFloor").Size
	clonedCoin.Position = Vector3.new(math.random(-(lobbyFloorSize.X / 2), lobbyFloorSize.X / 2), lobbyFloorSize.Y + 5, math.random(-(lobbyFloorSize.Z / 2), lobbyFloorSize.Z / 2))
	
	if chance < 50 then
		if chance >= 25 then
			clonedCoin.Name = "Uncommon Coin"
			clonedCoin.Color = Color3.fromRGB(37, 255, 44)
			toReward = 10
		elseif chance >= 10 then
			clonedCoin.Name = "Rare Coin"
			clonedCoin.Color = Color3.fromRGB(65, 151, 255)
			toReward = 25
		elseif chance >= 5 then
			clonedCoin.Name = "Epic Coin"
			clonedCoin.Color = Color3.fromRGB(146, 37, 255)
			toReward = 50
		elseif chance >= 1 then
			clonedCoin.Name = "Mythical Coin"
			clonedCoin.Color = Color3.fromRGB(255, 0, 0)
			toReward = 75
		elseif chance >= 0.5 then
			clonedCoin.Name = "Superior Coin"
			clonedCoin.Color = Color3.fromRGB(233, 244, 22)
			toReward = 100
		elseif chance >= 0.1 then
			clonedCoin.Name = "Luckiest Coin"
			clonedCoin.Color = Color3.fromRGB(37, 255, 44)
			toReward = 1000
		elseif chance >= 0.01 then
			clonedCoin.Name = "DIVINE COIN"
			clonedCoin.Color = Color3.fromRGB(253, 255, 130)
			toReward = 6969
		else
			--Something
		end
	elseif chance > 50 then
		clonedCoin.Name = "Coin"
		toReward = 1
	elseif chance == 50 then
		clonedCoin.Name = "GODLYCOIN"
		clonedCoin.Color = Color3.fromRGB(255,255,255)
		toReward = 10000
		local light = Instance.new("PointLight")
		light.Parent = clonedCoin
		light.Range = 60
		light.Brightness = 40
		light.Color = Color3.fromRGB(255,255,255)
		local proximityPrompt = Instance.new("ProximityPrompt")
		proximityPrompt.Parent = clonedCoin
		proximityPrompt.HoldDuration = 30
		proximityPrompt.ObjectText = "GOLDY COIN"
	else
		--Something
	end
	
	clonedCoin.Parent = workspace:WaitForChild("coinFolder")
--This is where I print toReward and it not result 0 and nil
end

A code for Giving coins to player

local coin = script.Parent

coin.Touched:Connect(function(part)
	if part.Parent:IsA("Model") and part.Parent:WaitForChild("Humanoid") then
		local userToGive = part.Parent.Name
		game.Players:WaitForChild(userToGive):WaitForChild("leaderstats"):WaitForChild("Coins").Value += coin:WaitForChild("rewardCoin").Value
		coin:Destroy()
	end
end)

Feel Free to ask me!

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Could you be a bit more specific on what the issue is.

I’m having a hard time understanding the problem.

What I understood is

  • Coin has IntValue (“rewardCoin”)
  • toReward holds rewardCoin

You commented “This is where I print toReward and it not result 0 and nil”. Are you expecting “0”? And getting nil?

I say “Not result 0 and nil” so I didn’t expecting these

What are you getting? Are you getting the expected value?

I mean I print(toReward) between this and I got the same Value as the chance set to Coins automatically

But when I print under the Coin Part, The value is 0

I still do not quite understand. But looking at the script the only thing I could see that may be causing an issue is this:

local toReward = clonedCoin:WaitForChild("rewardCoin").Value

toReward may be getting the Value itself as an Int, rather than the Property “Value”.
So declaring toReward as just

local toReward = clonedCoin:WaitForChild("rewardCoin")

May resolve the issue, and this would require you to then rewrite to have .Value included

toReward.Value = 1000
2 Likes

Maybe I should try this, idk if it work or not

Edited : It worked, Thanks :slight_smile:

1 Like

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