Get values from a touched part

I am attempting to get the values of a tool which touches a part.

This is my current code.

I am attempting to make the following:

First, check if the part touching is actually the card and not a players arm for example,
then check if the card has enough cash, if 0, then do error 5.
then check if the card is disabled, if disabled, then do error 2,
then check if the card is in use, if it is in use, then do error 3,
finally check if the card is valid, if invalid, do error 1.
If non of these errors are met, then do the following function,

function accept()

Any ideas?

function isCardValid()
    	if script.Parent.Parts.Body.EPad.Touched:Connect(function(hit)
    			if hit.Name == "Oyster Card" then
    				if hit.Cash == 0 then
    					script.Parent.Parts.Display.LED.SurfaceGui.TextLabel.Text = "SEEK ASSISTANCE 05"
    					script.Parent.Sounds.Error:Play()
    				end
    				if hit.Disabled == true then
    					script.Parent.Parts.Display.LED.SurfaceGui.TextLabel.Text = "SEEK ASSISTANCE 02"
    					script.Parent.Sounds.Error:Play()
    				end
    				if hit.Inuse == true then
    					script.Parent.Parts.Display.LED.SurfaceGui.TextLabel.Text = "SEEK ASSISTANCE 03"
    					script.Parent.Sounds.Error:Play()
    				end
    				if hit.Valid == false then
    					script.Parent.Parts.Display.LED.SurfaceGui.TextLabel.Text = "SEEK ASSISTANCE 01"
    					script.Parent.Sounds.Error:Play()
    				end
    			else
    				print ("not valid")
    			end
    		end
    ) then

You could try using NumberValues or Attributes to store the Cash value

The value needs to be different for different players in a game.

Is this still possible?

Yes, both ways should work if the number value is parented to the card or the attribute is set to the card

image

By adding the following attributes to this, will my code still work referring to the attributes instead of the values (the values no longer exist)

For example

if hit.Cash == true
With hit being the card that has touched the object

No, you’ll have to make a slight change in your code, e.g:

local Balance = hit:GetAttribute("Cash")

if (Balance ~= 0) then -- if cash isn't empty
    -- code

This appears to work. There is a problem with a bit of my previous code which is causing it to skip this however this works independently to everything else.