This function won't ever get called. No matter what I do

Sure! (I don’t know how to do that :smiley: )


:skull: Time is nil!!
also nothing spawned

Are making minigames this hard btw?

Ditto.
image

I can try make a quick system that works like it tomorrow ill just publish it to market.

That’s if I hop on here and see no one could solve it. There’s some really good coders on here so not all hopes gone.

ok ty!


:+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1:

1 Like

If i dont respond im sleeping. Make sure to put it on sale when you did it

Would it be possible to see the script?

Could you Add a warn inside the code like this and tell me the output? The function is definetly getting called but it seems like the if statement isn’t true or something is getting stuck inside the function.

Copy this code and let me know if all the checks appear

local function spawnMoles()

    warn("Check 1")
	if minigameStarted.Value == true then

		local holes = {1, 2, 3, 4, 5, 6, 7, 8}

		local numHoles = math.random(1, 5) -- change to a random number between 2 and 3

		for i = 1, numHoles do
             warn("Check 2 ")
			local index = math.random(1, #holes)

			local hole = holes[index]

			table.remove(holes, index)

			local moleType = moleTypes[math.random(1, #moleTypes)]

			local mole = moleType:Clone()
			local moleModel = mole:FindFirstChildOfClass("Model")
			mole.PrimaryPart = mole.Primary

			mole.Parent = workspace

			mole:MoveTo(holeDown[hole].Up.Position)
			mole:WaitForChild("PrimaryPart").Touched:Connect(function(part)
				if part and part.Parent and part.Parent:FindFirstChild("Humanoid") and part.Name == "Hammer" then
                    warn("Check 3")
					if moleModel.Name == "Mole" then
						score.Value = score.Value + 1
					elseif moleModel.Name == "GoldMole" then
						score.Value = score.Value + 3
					elseif moleModel.Name == "DiamondMole" then
						score.Value = score.Value + 5
					elseif moleModel.Name == "AngryMole" then
						score.Value = score.Value - 2
					elseif moleModel.Name == "BombMole" then
						score.Value = 0
					end
					scoreGui.Text = "Score: " .. score.Value
					moleModel.PrimaryPart:Destroy()
				end
			end)
			end
		end
	end

local player = nil


game.Players.PlayerAdded:Connect(function(plr)

	player = plr

end)

local button = script.Parent.Leaderboard.Leaderboard.Leaderboard.SurfaceGui.Frame.Start


local tool = game.ServerStorage.Hammer


wait(3)

local score = player:WaitForChild("Minigames"):WaitForChild("MoleHitters"):WaitForChild("Score")

local highScore = player:WaitForChild("Minigames"):WaitForChild("MoleHitters"):WaitForChild("Highscore")
local gui = player:WaitForChild("PlayerGui"):WaitForChild("Mole"):WaitForChild("Frame")
local mole = player:WaitForChild("PlayerGui"):WaitForChild("Mole")

local timer = gui:WaitForChild("Timer")

local scoreGui = gui:WaitForChild("Score")

local minigameStarted = script.MinigameStarted
local toolrn = nil


button.MouseButton1Click:Connect(function()
	print("Starting mole minigame for player", player.Name)

	if minigameStarted.Value == true then
		print("Minigame already started for player", player.Name)
		return
	end

	minigameStarted.Value = true

	button.Visible = false
	mole.Enabled = true


	-- give the player the tool
	local toolClone = tool:Clone()
	toolClone.Parent = player.Backpack
	toolrn = player.Backpack:WaitForChild("Hammer")

	-- reset score to 0
	score.Value = 0
	print("Reset score to 0 for player", player.Name)
end)

-- start the gameplay






scoreGui.Text = "Score: " .. score.Value

local function updateScore()
	if minigameStarted.Value == true then
		score.Value = score.Value + 1
		scoreGui.Text = "Score: " .. score.Value
	end
end

local timeLeft = 60

local function updateTime()
	if minigameStarted.Value == true then
		timeLeft = timeLeft - 1
		timer.Text = "Time left: " .. timeLeft
		if timeLeft == 0 then
			toolrn:Destroy()
			mole.Enabled = false
			minigameStarted.Value = false
			button.Visible = true
			timeLeft = 60
			timer.Text = "Time left: " .. timeLeft
			if score.Value > highScore.Value then
				highScore.Value = score.Value
				print("Updated highscore to", highScore.Value, "for player", player.Name)
			end
		end
	end
end

function UpdateTime2()
while timeLeft > 0 do

	updateTime()
	wait(1)
end
end
task.spawn(UpdateTime2)
local holeUp = script.Parent.TpMole -- Replace with actual path to holes

local holeDown = script.Parent.TpMole -- Replace with actual path to holes

local moleRegular = script.Parent.Moles.Mole

local moleGold = script.Parent.Moles.GoldMole

local moleDiamond = script.Parent.Moles.DiamondMole

local moleAngry = script.Parent.Moles.AngryMole

local moleBomb = script.Parent.Moles.BombMole

local moleTypes = {moleRegular, moleRegular, moleRegular, moleRegular, moleRegular, moleRegular, moleRegular, moleRegular, moleRegular, moleGold, moleGold, moleGold, moleAngry, moleAngry, moleBomb, moleDiamond} -- adjust moleTypes to have fewer rare mole types

local TweenService = game:GetService("TweenService")

local function spawnMoles()

	if minigameStarted.Value == true then

		local holes = {1, 2, 3, 4, 5, 6, 7, 8}

		local numHoles = math.random(1, 5) -- change to a random number between 2 and 3

		for i = 1, numHoles do

			local index = math.random(1, #holes)

			local hole = holes[index]

			table.remove(holes, index)

			local moleType = moleTypes[math.random(1, #moleTypes)]

			local mole = moleType:Clone()
			local moleModel = mole:FindFirstChildOfClass("Model")
			mole.PrimaryPart = mole.Primary

			mole.Parent = workspace

			mole:MoveTo(holeDown[hole].Up.Position)
			mole:WaitForChild("PrimaryPart").Touched:Connect(function(part)
				if part and part.Parent and part.Parent:FindFirstChild("Humanoid") and part.Name == "Hammer" then
					if moleModel.Name == "Mole" then
						score.Value = score.Value + 1
					elseif moleModel.Name == "GoldMole" then
						score.Value = score.Value + 3
					elseif moleModel.Name == "DiamondMole" then
						score.Value = score.Value + 5
					elseif moleModel.Name == "AngryMole" then
						score.Value = score.Value - 2
					elseif moleModel.Name == "BombMole" then
						score.Value = 0
					end
					scoreGui.Text = "Score: " .. score.Value
					moleModel.PrimaryPart:Destroy()
				end
			end)
			end
		end
	end
while true do
	print("poo")
	spawnMoles()
	print("YAY")
	wait(6)
	print("okkkkk")
end


WHAT THE HECK???

THIS IS MAGIC TY

(well the mole cframe is broken but ill fix it)

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.