Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

why wont this ship spawner/buy work?

function Freedom()
local RS = game:GetService("ReplicatedStorage")
local ship = RS:WaitForChild("Freedom")
local spawner = game.Workspace.Freedomspawn
local player = game.Players.LocalPlayer
local button = script.Parent
local price = 1000000
local stats = game.Players.LocalPlayer:WaitForChild("leaderstats")

if stats.Cash.Value >= price then
	stats.Cash.Value = stats.Cash.Value - price
	local cloned = ship:Clone()
	cloned.Parent = workspace
	cloned.CFrame = cloned.CFrame + (0,0,5)
end

end
end



 button.MouseButton1Click:connect(Freedom)

1 answer

NOTE | Almost everytime you use an if then statement you need to use else or elseif to let the game know... 'Okay, so if this doesn't work I would do this'

--Instructions to following script:

#1. Put the script in a local script and place it in the Button GUI

#2. Place Ship where you want in workspace

#3. Then place Ship in ServerStorage

RS = game:GetService("ReplicatedStorage")
ship = game.ServerStorage.Ship
spawner = game.Workspace.Spawn
plr = game.Players.LocalPlayer
button = script.Parent
price = 1000000
stats = game.Players.LocalPlayer.leaderstats.Cash

script.Parent.MouseButton1Click:Connect(function(onClick)
	if Cash.Value >= price then
		Cash.Value = Cash.Value - price
		ship:Clone().Parent = game.Workspace
	elseif Cash.Value <= price then
		Cash.Value = Cash.Value - 0
		plr.Character.Humanoid.Health = plr.Character.Humanoid.Health - 10 --Optional
	end
end)

2 comments

0

This is false, as if it doesn't match the requirements, it will end the script there.

0

It usually doesn't work for me unless I use else or elseif. That's why I said 'Almost'

This discussion is preserved as it was. New answers, comments, and votes are closed.