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)
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?
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