Im working on a mole minigame. That gives a tool to the player and creates a box to prevent players from teleporting. Although the script isnt working at all. nothing prints at all. Also I want a better way of preventing players from interferring from the minigame. (Or atleast turn off the button for use until the minigame is over for the player.)
local Players = game:GetService("Players")
local button = script.Parent.Leaderboard.Leaderboard.Leaderboard.SurfaceGui.Frame.Start
local tool = script.Parent.Hammer.Hammer
local function startMoleMinigame(player)
print("Starting mole minigame for player", player.Name)
local score = player:WaitForChild("Minigames"):WaitForChild("MoleHitters"):WaitForChild("Score")
local highScore = player:WaitForChild("Minigames"):WaitForChild("MoleHitters"):WaitForChild("Highscore")
local minigameStarted = player:WaitForChild("Minigames"):WaitForChild("MoleHitters"):WaitForChild("MinigameStarted")
if minigameStarted.Value == true then
print("Minigame already started for player", player.Name)
return
end
minigameStarted.Value = true
button.Visible = false
-- spawn the box that teleports everyone away except the player
local box = Instance.new("Part")
box.Size = Vector3.new(10, 10, 10)
box.Position = Vector3.new(0, 50, 0) -- adjust this position to where you want the box to spawn
box.Anchored = true
box.CanCollide = false
box.Transparency = 1
box.Parent = game.Workspace
local function onTouched(part)
if part:IsA("BasePart") and part.Parent:IsA("Model") and part.Parent ~= player.Character then
if part.Parent == player.Character then
-- teleport the player to a safe location
part.Parent:MoveTo(Vector3.new(0, 10, 0))
else
-- teleport other players away
part.Parent:MoveTo(Vector3.new(0, 1000, 0))
part.Parent.HumanoidRootPart.CanCollide = true -- allow other players to collide with each other
end
box.Touched:Disconnect() -- disconnect the event to prevent further teleportations
end
end
box.Touched:Connect(onTouched)
-- give the player the tool
local toolClone = tool:Clone()
toolClone.Parent = player.Backpack
-- reset score to 0
score.Value = 0
print("Reset score to 0 for player", player.Name)
-- update highscore if necessary
if score.Value > highScore.Value then
highScore.Value = score.Value
print("Updated highscore to", highScore.Value, "for player", player.Name)
end
end
button.Activated:Connect(function()
local player = Players:GetPlayers()
if player then
startMoleMinigame(player)
end
end)
Thank you
(Im also working on a leaderboard)