Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

why wont this ship spawner/buy work?

Asked by 7 years ago
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

Log in to vote
0
Answered by 7 years ago

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)
0
This is false, as if it doesn't match the requirements, it will end the script there. commag 228 — 7y
0
It usually doesn't work for me unless I use else or elseif. That's why I said 'Almost' Goldenkings11 -11 — 7y
Ad

Answer this question