Its working in the studio but not in the game? Wtf?!

The script i used :

local player = game.Players.LocalPlayer --Assuming the script is a localscript, you can shorten this.
local cost = 250

script.Parent.MouseButton1Click:connect(function()
local leaderstats = player:FindFirstChild("leaderstats") --You don't need nearly as many if statements as you had, since if the code results in error, it will stop running and can be recalled when the button is pressed again.
local money = leaderstats:FindFirstChild("Money")
if money.Value >= cost then
local spawncar = game.Lighting["BMWM3"]:clone()
spawncar.Parent = workspace
spawncar:MakeJoints() --Assuming you already have proper welds established in the car.
money.Value = money.Value - 250
script.Parent.Text = "Bought"
else
script.Parent.FontSize = 6
script.Parent.Text = "Not enough $"
end
end)

4 comments

0

Use Localscript

0

Or use TextLabel instead of TextBox

0

Thanks! working!

0

Please refrain from using swears; it may hurt someone's feelings. :c