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

Script for GUI wont work?

Asked by
CjInc 5
9 years ago

So, to further explain my question, here's a new post.

I whipped up a leaderboard, GUI button, and a script that, when the button is clicked, you will receive that certain vehicle if you have enough money. But, for some reason it wont work. I parented the vehicle model to 'Lighting,' checked for spelling errors, etc. I don't know what's wrong.

Heres the code.

local model = game.Lighting.Omicron
local character = game.Players.LocalPlayer.Character
local Currecy = game.Players.LocalPlayer.leaderstats.Money
local Price = 0

function onClicked()
if Currency.Value >= Price then
Currency.Value = Currency.Value - Price
local a = model:clone()
a.Parent = game.Workspace
wait()
a:MakeJoints()
wait()
a:MoveTo(character.Torso.Position + Vector3.new(0,0,10))
end
end
script.Parent.MouseButton1Click:connect(onClicked)

1 answer

Log in to vote
0
Answered by 9 years ago

There are several problems. Your variable is spelt "Currecy" instead of "Currency"

local Currecy = game.Players.LocalPlayer.leaderstats.Money

Should become:

local Currency = game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("Money")

Another issue is with:

local character = game.Players.LocalPlayer.Character

This should become:

repeat wait() until game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character.Parent
local character = game.Players.LocalPlayer.Character

There is no need for a wait() before :MakeJoints(). You should also move the vehicles from Lighting, in to ReplicatedStorage.

local model = game.ReplicatedStorage:WaitForChild("Omicron")

All together:

local model = game.ReplicatedStorage:WaitForChild("Omicron")
repeat wait() until game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character.Parent
local character = game.Players.LocalPlayer.Character
local Currency = game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("Money")
local Price = 0

function onClicked()
if Currency.Value >= Price then
Currency.Value = Currency.Value - Price
local a = model:clone()
a.Parent = game.Workspace
a:MakeJoints()
wait()
a:MoveTo(character.Torso.Position + Vector3.new(0,0,10))
end
end
script.Parent.MouseButton1Click:connect(onClicked)
0
Thank you, but it still wont work. CjInc 5 — 9y
0
Any error? epicbreaker 95 — 9y
Ad

Answer this question