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.
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.