Here is my script so far
local ting = 0 function onTouched(hit) if ting == 0 then ting = 1 check = hit.Parent:FindFirstChild("Humanoid") if check ~= nil then local user = game.Players:GetPlayerFromCharacter(hit.Parent) local stats = user:findFirstChild("leaderstats") if stats ~= nil then local cash = stats:findFirstChild("Cash") cash.Value = cash.Value -100 wait(10) end end ting = 0 end end script.Parent.Touched:connect(onTouched) shirtid = "rbxassetid://" pantsid = "rbxassetid://" script.Parent.Touched:connect(function(hit) if hit.Parent:findFirstChild("Humanoid")then char = hit.Parent if char:findFirstChild("Shirt") then char.Shirt.ShirtTemplate = shirtid else a = Instance.new("Shirt", char) a.Name = "Shirt" a.ShirtTemplate = shirtid end if char:findFirstChild("Pants") then char.Pants.PantsTemplate = pantsid else b = Instance.new("Pants", char) b.Name = "Pants" b.PantsTemplate = pantsid end end end) pantsid = "rbxassetid://" script.Parent.Touched:connect(function(hit) if hit.Parent:findFirstChild("Humanoid")then char = hit.Parent if char:findFirstChild("Shirt") then char.Shirt.ShirtTemplate = shirtid else a = Instance.new("Shirt", char) a.Name = "Shirt" a.ShirtTemplate = shirtid end if char:findFirstChild("Pants") then char.Pants.PantsTemplate = pantsid else b = Instance.new("Pants", char) b.Name = "Pants" b.PantsTemplate = pantsid end end end)
But it just gives me the cloths when I have 0 I need it so it does not let them have it if they have enough I also took out the cloths Ids here
Remember, the :connect
and :findFirstChild
is deprecated, you can use :Connect
and :FindFirstChild
, Use local VARIABLE
for use variables with more efficiently
For this is simple, you need to detect the current value and if more or equal of price, start the function
Its simple here is a example:
local number1 = 50 local number2 = 100 if number1 >= number2 then warn("Number 1 have more than Number 2") else warn("Number 2 have more than Number 1") end
And you need create a function for give
Example:
function create(name) local part = Instance.new("Part", workspace) part.Name = name return part end create("Test-Block")
You can use this script:
local ting = 0 local price = 100 -- Set the price. shirtid = "rbxassetid://" -- Set the id pantsid = "rbxassetid://" -- Set the id function pants_and_shirt(char,shirt_id,pants_id) if char:FindFirstChild("Shirt") then char.Shirt.ShirtTemplate = shirt_id else local a = Instance.new("Shirt", char) a.Name = "Shirt" a.ShirtTemplate = shirt_id end wait() if char:FindFirstChild("Pants") then char.Pants.PantsTemplate = pants_id else local b = Instance.new("Pants", char) b.Name = "Pants" b.PantsTemplate = pants_id end end function onTouched(hit) if ting == 0 then ting = 1 local check = hit.Parent:FindFirstChild("Humanoid") if check ~= nil then local user = game:GetService("Players"):FindFirstChild(hit.Parent.Name) local stats = user:FindFirstChild("leaderstats") if stats ~= nil then if stats.Value >= price then pants_and_shirt(user.Character,shirtid,pantsid) local cash = stats:FindFirstChild("Cash") cash.Value = cash.Value - price end end end wait(10) -- For remove debounce, remove this ( wait(10) ) ting = 0 end end script.Parent.Touched:Connect(onTouched)
Hope it helped :D
Any errors? tell-me on comments.