Hello my name is Juice_ED and I am fairy new scripter and I don’t know how to make my code better/clean it, I have searched youtube’s video and nothing came up, here is some of my code (I know it’s bad)
local player = game.Players.LocalPlayer
local part = workspace.Checker.Part
local Money = workspace.Money
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local gold = Instance.new("IntValue")
gold.Name = "Cash"
gold.Value = 0
gold.Parent = leaderstats
end)
part.Touched:Connect(function(hit)
player = game.Players:FindFirstChild(hit.Parent.Name)
if player then
local leaderstats = player:WaitForChild("leaderstats")
local Cash = leaderstats:FindFirstChild("Cash")
Cash.Value = Cash.Value + Money.Value.Value
Money.Value.Value = 0
end
end)
local BillboardGUI = script.Parent.RedPart.BillboardGui
local RepliactedStorage = game:WaitForChild("ReplicatedStorage")
local Wall = RepliactedStorage.Wall2.Part
local MoneyValue = script.Parent.Value.Value
local NameValue = script.Parent.NameValue.Value
local player = game.Players.LocalPlayer
BillboardGUI.Text.Text = NameValue.. " Cost: "..MoneyValue
script.Parent.RedPart.Touched:Connect(function(hit)
player = game.Players:FindFirstChild(hit.Parent.Name)
if player then
local leaderstats = player:WaitForChild("leaderstats")
local Cash = leaderstats:FindFirstChild("Cash")
if Cash.Value >= MoneyValue then
Cash.Value = Cash.Value - MoneyValue
local ClonedWall = Wall:Clone()
ClonedWall.Parent = workspace
ClonedWall.Position = Vector3.new(-71.201, 1.5, 4.674)
script.Parent.RedPart:Destroy()
script.Parent.Part:Destroy()
else
print("Not Enough")
BillboardGUI.Text.Text = "Not Enough"
wait(5)
BillboardGUI.Text.Text = NameValue.." Cash: "..MoneyValue
end
end
end)
local BillboardGUI = script.Parent.RedPart.BillboardGui
local RepliactedStorage = game:WaitForChild("ReplicatedStorage")
local Upgarder = game.ReplicatedStorage.Upgrader2
local MoneyValue = script.Parent.Value.Value
local NameValue = script.Parent.NameValue.Value
local player = game.Players.LocalPlayer
BillboardGUI.Text.Text = NameValue.. " Cost: "..MoneyValue
script.Parent.RedPart.Touched:Connect(function(hit)
player = game.Players:FindFirstChild(hit.Parent.Name)
if player then
local leaderstats = player:WaitForChild("leaderstats")
local Cash = leaderstats:FindFirstChild("Cash")
if Cash.Value >= MoneyValue then
Cash.Value = Cash.Value - MoneyValue
local ClonedUpgarder = Upgarder:Clone()
ClonedUpgarder.Parent = workspace
script.Parent.RedPart:Destroy()
script.Parent.Part:Destroy()
else
print("Not Enough")
BillboardGUI.Text.Text = "Not Enough"
wait(5)
end
end
end)