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

What´s wrong with this script?

Asked by 10 years ago

Hi there biocommand here with another doubt, I made a ScreengGui and from there I inserted an Imagebutton and inside the ImageButton I inserted a script so the order is like this ScreenGui>ImageButton>Script Now what I wanted to do is the when you click the ImageButton a car gets cloned from lighting and inserted on workspace if you have more or equal 5 points heres the script:

script.Parent.MouseButton1Down:connect(function()
     -- Check the player has a stats object
    local stats = player:FindFirstChild('leaderstats')
    if not stats then return end

    -- And that the stats object contains a gold member
    local gold = stats:FindFirstChild('Score')
    if not gold then return end
if gold.Value >= 5 then -- 5 is the amount of gold you need to purchase this weapon
clon = game.Lighting.Car2:Clone()
clon.Parent = Workspace
clon:MakeJoints()
gold.Value = gold.Value - 5 -- subtract the amount of gold you need to purchase
        end
end)
0
Is player defined? Link43758 175 — 10y
0
ooohh..... biocommand 30 — 10y
0
Midnight how would I define player? biocommand 30 — 10y

2 answers

Log in to vote
0
Answered by 10 years ago
script.Parent.MouseButton1Down:connect(function(player) --I think this is where the problem was. I'm not sure.
     -- Check the player has a stats object
    local stats = player.Parent:FindFirstChild('leaderstats')
    if not stats then return end

    -- And that the stats object contains a gold member
    local gold = stats:FindFirstChild('Score')
    if not gold then return end
if gold.Value >= 5 then -- 5 is the amount of gold you need to purchase this weapon
clon = game.Lighting.Car2:Clone()
clon.Parent = Workspace
clon:MakeJoints()
gold.Value = gold.Value - 5 -- subtract the amount of gold you need to purchase        
    end
end)

--I will delete this answer if it is incorrect.

Also, if this doesn't work, could you please give us the output error that Studio should give out?

0
It didn´t worked I checked output but nothing biocommand 30 — 10y
0
What about now? Does it work? fahmisack123 385 — 10y
0
No :( biocommand 30 — 10y
0
I'm out of ideas. Sorry. fahmisack123 385 — 10y
0
Maybe take out the "if not stats then return end"? I think that could work. fahmisack123 385 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

I think you need to use "FindFirstChild" and "player" is not defined, the first argument passed from that method is not "player", try this in a LocalScript!

local player = game.Players.LocalPlayer
script.Parent.MouseButton1Down:connect(function(par1)
    local stats = player.Parent:FindFirstChild('leaderstats')
    if not stats then return end

    -- And that the stats object contains a gold member
    local gold = stats:FindFirstChild('Score')
    if not gold then return end
if gold.Value >= 5 then -- 5 is the amount of gold you need to purchase this weapon
clon = game.Lighting:FindFirstChild("Car2"):Clone()
clon.Parent = game.Workspace -- You missed "game."
clon:MakeJoints()
gold.Value = gold.Value - 5 -- subtract the amount of gold you need to purchase        
    end
end)

--I will delete this answer if it is incorrect.

This should work

Answer this question