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

What´s wrong with this script?

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)

3 comments

0

Is player defined?

0

ooohh.....

0

Midnight how would I define player?

2 answers

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?

5 comments

0

It didn´t worked I checked output but nothing

0

What about now? Does it work?

0

No :(

0

I'm out of ideas. Sorry.

0

Maybe take out the "if not stats then return end"? I think that could work.

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

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