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

How could I make this script find the correct cash?

model = script.Parent.Parent.Model
price = 100
blarg = script.Parent.Parent.Name
copy = model:Clone()
wait(1)
model:Destroy()
Owner = script.Parent.Parent.Parent.Owner
local safety = 0
function onTouched(hit)
	if safety == 0 then
		safety = 1
		check = hit.Parent:FindFirstChild("Humanoid")
		if check ~= nil then
			if hit.Parent.Name == Owner.Value then
				--------------------------------- Here's the problem----------
				guy = hit.Parent.Name
				local cash = Workspace.Cash.guy
				----------------------------------------------------------
				if cash.Value > (price-1) then
					cash.Value = cash.Value-price
					copy.Parent = script.Parent.Parent
					copy:MakeJoints()
					script.Parent.Parent.Humanoid:Destroy()
					script.Parent:Destroy()
				elseif cash.Value < (price-1) then
					script.Parent.Parent.Name = ("You still need $"..(price-cash.Value).." to purchase this.")
					wait(2)
					script.Parent.Parent.Name = blarg
				end
			end
		end
		safety = 0
	end
end

script.Parent.Touched:connect(onTouched)

The problem here is that when a player joins the game I create a new NumberValue in a model called Cash in Workspace. The NumberValue's name is their name. How would I get it to check the NumberValue with their name when it checks how much money they have? I selected the area in the script where I tried to make it work.

2 comments

0

If 'guy' is a value, you would do             local cash = Workspace.Cash.guy.Value

0

Any errors? Also, on line 19 try 'if cash.Value >= price then' and line 25 try 'elseif cash.Value <= price then'.

1 answer

✓ Accepted answer

Here you go, let me know if it works.

** Edit :

I noticed I had cash instead of Cash - Fixed **

model = script.Parent.Parent.Model
price = 100
blarg = script.Parent.Parent.Name
copy = model:Clone()
wait(1)
model:Destroy()
Owner = script.Parent.Parent.Parent.Owner
local safety = 0
function onTouched(hit)
    if safety == 0 then
        safety = 1
        check = hit.Parent:FindFirstChild("Humanoid")
        if check ~= nil then
            if hit.Parent.Name == Owner.Value then
                --------------------------------- Here's the problem----------
                guy = game.Players:GetPlayerFromCharacter(hit.Parent)
                local cash = Workspace.Cash[guy.Name]
                ----------------------------------------------------------
                if cash.Value > (price-1) then
                    cash.Value = cash.Value-price
                    copy.Parent = script.Parent.Parent
                    copy:MakeJoints()
                    script.Parent.Parent.Humanoid:Destroy()
                    script.Parent:Destroy()
                elseif cash.Value < (price-1) then
                    script.Parent.Parent.Name = ("You still need $"..(price-cash.Value).." to purchase this.")
                    wait(2)
                    script.Parent.Parent.Name = blarg
                end
            end
        end
        safety = 0
    end
end

script.Parent.Touched:connect(onTouched)

1 comment

0

Worked! Awesome man!

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