Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How could I make this script find the correct cash?

Asked by 10 years ago
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.

0
If 'guy' is a value, you would do             local cash = Workspace.Cash.guy.Value Tempestatem 884 — 10y
0
Any errors? Also, on line 19 try 'if cash.Value >= price then' and line 25 try 'elseif cash.Value <= price then'. GoldenPhysics 474 — 10y

1 answer

Log in to vote
1
Answered by
TopDev 0
10 years ago

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)

0
Worked! Awesome man! jaytheidiot 60 — 10y
Ad

Answer this question