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

Script won't do anything?

Sorry for all the help needed today guys.

I'm making a coin pusher. When someone clicks the insert button (part with a click-detector) it costs them 1 'coin' and the coin is created and dropped.

Here's what I have so far:

Insert = script.Parent
Upgradecost = 1

local ting = 0
function onClicked(click)
    if ting == 0 then
    check = click.Parent:FindFirstChild("Humanoid")
    if check ~= nil then
        local user = game.Players:GetPlayerFromCharacter(click.Parent)
        local stats = user:findFirstChild("leaderstats")
        if stats ~= nil then
            local cash = stats:findFirstChild("Coins")
            if cash.Value > (Upgradecost-1) then
                cash.Value = cash.Value - Upgradecost
                script.Parent.Parent.Parent.Purchase:play()
						local h = click.Parent:findFirstChild("Humanoid")
								if h~=nil then
          						  Coin = Instance.new("Part", game.Workspace)
							    	Coin.Shape = ("Cylinder")
									Coin.BrickColor = BrickColor.new("Gold")
									Coin.Size = Vector3.new(0.2, 2, 2)
									Coin.Position = Insert.Position - Vector3.new(0, 7.7, 0)
									Coin.Reflectance = 0.61
									Coin.Name = "Working"
									Coin.Rotation = Vector3.new(90, 0, 90)
									wait(1)				
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
					end
				end
			end
		end
	end

Any ideas? No output or anything.

4 comments

0

Lines 16-17 are duplicates of lines 7-8. On line 13, use cash.Value >= UpgradeCost. And most importantly, CONNECT THE FUNCTION OUTSIDE OF THE FUNCTION ITSELF. Seriously, I can't stress that enough.

0

Oh my gosh! Okay I did it. But it still won't work!

0

Put a print after each if telling what you checked. Then tell us the output

0

Shouldn't your listener be outside the function...

1 answer

The MouseClick event of ClickDetectors takes the player who clicked as an argument. You're looking for click.Parent, and trying to get the player from that, when you already have the player.

Your connection line is also inside of your function. So, the function won't run unless the function runs. Weird.

Also, I'd try printing in different places to see what's running and what isn't, if the problem persists.

Insert = script.Parent
Upgradecost = 1

local ting = 0
function onClicked(click)
	if ting == 0 then
		check = game.Workspace:FindFirstChild(click) -- May have to use click.Name, I am unsure.
		if check ~= nil then
			local user = click
			local stats = user:findFirstChild("leaderstats")
			if stats ~= nil then
				local cash = stats:findFirstChild("Coins")
				if cash.Value > (Upgradecost-1) then
					cash.Value = cash.Value - Upgradecost
					script.Parent.Parent.Parent.Purchase:play()
					Coin = Instance.new("Part", game.Workspace)
					Coin.Shape = ("Cylinder")
					Coin.BrickColor = BrickColor.new("Gold")
					Coin.Size = Vector3.new(0.2, 2, 2)
					Coin.Position = Insert.Position - Vector3.new(0, 7.7, 0)
					Coin.Reflectance = 0.61
					Coin.Name = "Working"
					Coin.Rotation = Vector3.new(90, 0, 90)
					wait(1)             
				end
			end
		end
	end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked) -- This should be here, so the script can run it.

Hope this helped.

EDIT: Added the fix @GoldenPhysics mentioned, didn't even notice that.

4 comments

0

This worked after I changed it to "click.Name", however, although it will take money from the player, it will not create the Coin.

0

Try it now, added in what GP mentioned.

0

It works perfectly! Thank you! You should seriously check out this coin pusher though, it's surprisingly legitimate.

0

No problem, make sure you edit line 13 as @GoldenPhysics said.

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