You can write your topic however you want, but you need to answer these questions:
-
Need the sharks to be able to tag minnows Keep it simple and clear!
-
The Sharks are not tagging the minnows for reason, i mean im defintely bad at scripting so ive hardly done most of it myeslf, but everything works but the tagging system Include screenshots / videos if possible!
-
I’ve tried tons of debugging messages, fixing other issues which i eventually fixed, but i cant seem to fix the tagging issue?
There is collision groups for sharks, minnows, and neutral that are properly set up.
'local Playerslocal Players = game:GetService("Players")
local GameEvents = require(game.ReplicatedStorage:WaitForChild("GameEvents"))
local TeamsModule = require(script.Parent:WaitForChild("TeamsManager"))
local MapManager = require(script.Parent:WaitForChild("MapManager"))
local SharkManager = {}
-- Variables
local currentShark = nil
print("🦈 SharkManager Script Loaded!")
-- Function to handle Shark tagging Minnows
local function onSharkTouch(hit)
print("🦈 Touch detected with:", hit.Name)
local character = hit.Parent
if not character then
print("❌ No character found from hit")
return
end
local player = Players:GetPlayerFromCharacter(character)
if not player then
print("❌ No player found from character")
return
end
-- Don't tag if it's the shark itself
if player == currentShark then
print("❌ Can't tag self")
return
end
-- Only tag if the player is a Minnow
if not player.Team or player.Team.Name ~= "Minnow" then
print("❌ Not a Minnow:", player.Name, "Team:", player.Team and player.Team.Name or "None")
return
end
print("✅ Valid tag on Minnow:", player.Name)
SharkManager.TagPlayer(character)
end
-- Function to tag the player
function SharkManager.TagPlayer(character)
print("🎯 Attempting to tag player...")
local player = Players:GetPlayerFromCharacter(character)
if not player then
print("❌ Failed to get player from character")
return
end
print("🎯 Tagging player:", player.Name)
-- Reset player to neutral team
TeamsModule:SetPlayerAsNeutral(player)
print("✅ Set player to neutral team")
-- Fire the tag event
GameEvents.Events.PlayerTagged:FireAllClients(player)
-- Teleport the player to spawn
local spawnLocation = workspace:FindFirstChild("SpawnLocation")
if spawnLocation then
local primaryPart = character.PrimaryPart
if primaryPart then
-- Set collision group to Neutral before teleporting
for _, part in ipairs(character:GetDescendants()) do
if part:IsA("BasePart") then
part.CollisionGroup = "Neutral"
end
end
character:SetPrimaryPartCFrame(spawnLocation.CFrame + Vector3.new(0, 5, 0))
print("✅ Teleported", player.Name, "to spawn")
else
print("❌ No PrimaryPart for:", player.Name)
end
else
print("❌ No SpawnLocation found!")
end
end
-- Function to setup Shark tagging
function SharkManager.setupSharkTagging(sharkCharacter)
print("🦈 Setting up shark tagging...")
if not sharkCharacter then
print("❌ No shark character provided!")
return
end
-- Create a touch detector part
local detector = Instance.new("Part")
detector.Name = "SharkTouchDetector"
detector.Transparency = 1
detector.CanCollide = false
detector.Size = Vector3.new(8, 8, 8)
detector.CollisionGroup = "Sharks" -- Set collision group for detector
detector.Parent = sharkCharacter
-- Remove any existing detector
local existingDetector = sharkCharacter:FindFirstChild("SharkTouchDetector")
if existingDetector then
existingDetector:Destroy()
end
-- Weld to HumanoidRootPart
local hrp = sharkCharacter:WaitForChild("HumanoidRootPart")
local weld = Instance.new("WeldConstraint")
weld.Part0 = hrp
weld.Part1 = detector
weld.Parent = detector
-- Position it
detector.CFrame = hrp.CFrame
-- Connect touch detection
detector.Touched:Connect(onSharkTouch)
print("✅ Shark tagging setup complete")
end
-- [Rest of your functions remain the same]
function SharkManager.TeleportShark()
print("🚀 Attempting to teleport shark...")
if not currentShark then
print("❌ No current shark to teleport")
return
end
local character = currentShark.Character
if not character or not character.PrimaryPart then
print("❌ Shark character or PrimaryPart missing")
return
end
local mapFolder = workspace:FindFirstChild("Maps")
local currentMap = MapManager.GetCurrentMap()
if not currentMap then
print("❌ No current map")
return
end
local selectedMapFolder = mapFolder and mapFolder:FindFirstChild(currentMap.Name)
local sharkSpawn = selectedMapFolder and selectedMapFolder:FindFirstChild(currentMap.SharkSpawnLocation)
if sharkSpawn then
character:SetPrimaryPartCFrame(sharkSpawn.CFrame + Vector3.new(0, 5, 0))
print("✅ Shark teleported to:", currentMap.Name, "->", currentMap.SharkSpawnLocation)
else
print("❌ Shark spawn location missing!")
end
end
function SharkManager.ChooseNewShark()
print("🎲 Choosing new shark...")
local players = Players:GetPlayers()
if #players == 0 then
print("❌ No players to choose from")
return
end
local randomShark = players[math.random(1, #players)]
SharkManager.SetCurrentShark(randomShark)
TeamsModule:SetPlayerAsShark(randomShark)
print("🦈 New Shark chosen:", randomShark.Name)
-- Assign all other players as Minnows
for _, player in ipairs(players) do
if player ~= randomShark then
TeamsModule:SetPlayerAsMinnow(player)
print("🐠 Set player as Minnow:", player.Name)
end
end
if randomShark.Character then
print("🦈 Setting up initial shark tagging")
task.wait(0.5) -- Wait for collision groups to be set
SharkManager.setupSharkTagging(randomShark.Character)
end
randomShark.CharacterAdded:Connect(function(character)
print("🦈 Shark's character added - setting up tagging")
task.wait(0.5) -- Wait for collision groups to be set
if currentShark == randomShark then
SharkManager.setupSharkTagging(character)
end
end)
task.wait(1)
SharkManager.TeleportShark()
end
function SharkManager.Reset()
print("🔄 Resetting shark manager...")
currentShark = nil
GameEvents.IsItValue.Value = ""
TeamsModule:ResetTeams()
print("✅ Reset complete")
end
function SharkManager.GetCurrentShark()
return currentShark
end
function SharkManager.SetCurrentShark(player)
if player and player:IsA("Player") then
currentShark = player
GameEvents.IsItValue.Value = player.Name
print("👑 New Shark assigned:", player.Name)
else
print("❌ Invalid player provided for shark!")
end
end
Players.PlayerAdded:Connect(function(player)
print("👋 New player joined:", player.Name)
player.CharacterAdded:Connect(function(character)
task.wait(0.5)
if player == currentShark then
print("🦈 Setting up tagging for new shark character")
SharkManager.setupSharkTagging(character)
end
end)
end)
print("🔍 Checking for existing shark...")
if currentShark and currentShark.Character then
print("🦈 Setting up tagging for existing shark")
SharkManager.setupSharkTagging(currentShark.Character)
end
return SharkManager'