Attempting to index number with "Value"?

I have a door script where whenever a player with the right amount of money (rc) touches the door it allows them to pass through. The code works when I tested it but it keeps telling me in output [11:12:16.443 - Workspace.Map.Map1.Doors.Door1.Script:12: attempt to index number with ‘Value’]. I know this has something to do with the fact my script has rc.Value while rc is a number, but I dont know how to fix this. Every time I try it just ruins the code. Can someone help me with this?

local rc = 500

local debounce = true
script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player.leaderstats.Cash.Value >= rc then
			if debounce then
				debounce = false
				script.Parent.Transparency = 0.5
				script.Parent.CanCollide = false
				if rc.Value <= rc then
					script.Parent.Transparency = 0.3
					script.Parent.CanCollide = true
				end
			end
		end
	end
end)
3 Likes

This is your issue. “rc” is not something like a number/int value, so it has no “.Value”. It is only a variable.

I know this, but it’s the only thing that works rn. I don’t know how to change that without ruining the code.

1 Like

I am confused what that part is even supposed to do. You are trying to check if a variable is less than or equal to itself?

I was following a tutorial and thats what they did. That part is supposed to make it where if you don’t have 500+ coins it wont let you pass through the door.

So do you want the the transparency to go to .3 if the player’s cash is less than rc?

Yes, if the player doesn’t have 500 or more I want the door to set CanCollide to true and Transparency to 0.3 without having to use rc.Value.

1 Like
else
— Do door transparency and collide here

Ok, so do this instead to fix it:

Didn’t work, it lets me pass through the door if I have less than 500.

1 Like

Is the part’s CanCollide automatically set to false? If so, then make it auto can collide true.

The parts CanCollide is set to true.

1 Like

I just tested it in studio and it works as intended. Am I missing something?

It didn’t say the error in the output?

Nope, there are no errors at all.

1 Like

Use this code exactly. Just delete all your code and use this

local rc = 500

local debounce = true
script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player.leaderstats.Cash.Value >= rc then
			if debounce then
				debounce = false
				script.Parent.Transparency = 0.5
				script.Parent.CanCollide = false
			end
        else
             script.Parent.Transparency = 0.3
			script.Parent.CanCollide = true
		end
	end
end)
2 Likes

It didn’t display an error but it lets me walk through with only 100 coins.

1 Like

It doesn’t do that for me at all.

Wait nvm, I just had a friend test it for me on Roblox. It did work. For some reason It lets me pass maybe because it added up the value of my other weight plus my 300 dollars to make 500. Thank you for taking so much time to help.

1 Like