Here is my code:
local sound = game.workspace.Money
local cost = 0
local touchedalready = 0
local player = game.Players.LocalPlayer
workspace.FloorExtension.Touched:Connect(function(hit)
repeat wait() until _G.button1bought == true
script.Parent.Transparency = 0
script.Parent.CanCollide = true
script.Parent.Touched:Connect(function(hit)
if hit and hit.Parent and hit.Parent:FindFirstChildOfClass("Humanoid") and game.Players:GetPlayerFromCharacter(hit.Parent) then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local MoneyValue = leaderstats:FindFirstChild("Money")
if MoneyValue then
if MoneyValue.Value >= cost and touchedalready then
touchedalready = 1
MoneyValue.Value = MoneyValue.Value - cost
sound:Play()
wait(0.01)
script.Parent:Destroy()
end
end
end
end
end)
end)
This doesn't work since it never sets the transparency to 0 or making it so you can collide with it, meaning its not working and i don't know how to get the button1bought variable since its not on leaderstats so i can't use that, and i know not to use _G but i don't know what else i can use for the variable.
