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.
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)