I have a function called shoot player, it clones a warning object onto the floor beneath the player. If the player is touching it after the Touched event is ran, they will get deducted currency (Laughs). However my issue is that the touched event rarley fires with more than one player in the game, if the player is playing the game alone the touched event fires perfectly. I’ve ran prints and came to the conclusion that the .Touched event is not being fired at all (99% of the time) with more than one player, but runs almost every time with only one player. There is only one player touching the part a time.
Shoot Player Function
local function ShootPlayer()
local warningTouched = false
canWork = false
local warning = game.ReplicatedStorage.Bosses.Warning:Clone()
warning.Parent = workspace
local offset = Vector3.new(0, -3, 0)
warning.CFrame = CFrame.new(char.PrimaryPart.Position) * CFrame.new(offset) * CFrame.Angles(math.rad(0), math.rad(0), math.rad(90))
shoot:Play()
walk:Stop()
wait(0.3)
game.SoundService.Bosses.WildWest.Shot:Play()
game.SoundService.Bosses.WildWest.Explosion:Play()
warning.Touched:Connect(function(hit)
print("THE THING IS TOCUHED BT" .. hit.Name)
local playerToBeHit = game.Players:GetPlayerFromCharacter(hit.Parent)
if playerToBeHit and not warningTouched and playerToBeHit.Name == player.Name then
warningTouched = true
table.insert(playersInside, playerToBeHit)
print("Player Hit By Bullet")
end
end)
for i, playerToDeductFrom in ipairs(playersInside) do
if playerToDeductFrom.leaderstats.Laughs.Value >= 50 then
playerToDeductFrom.leaderstats.Laughs.Value -= 50
print("Deducted")
game.ReplicatedStorage.RemoteEvents.Notification:FireClient(player,"Hit by Bullet -50 Laughs", 3, true)
end
table.remove(playersInside, i)
end
task.wait()
warningTouched = false
warning:Destroy()
task.wait()
shoot:Stop()
task.wait(1)
canWork = true
walk:Play()
end
Get Richest Player Function
local function GetRichestPlayer()
local most_coins, richest_player = -1, nil
local players = Players:GetPlayers()
for i=1,#players do
local player = players[i]
local player_coins = player.leaderstats.Laughs and player.leaderstats.Laughs.Value or nil
if player_coins and player_coins > most_coins then
most_coins = player_coins
richest_player = player
end
end
return most_coins, richest_player
end
How ShootPlayer() is called.
task.spawn(function()
while wait(math.random(5, 10)) do
for i=0, math.random(1, 55) do
spawn(ShootPlayer)
wait(0.15)
end
end
end)
Warning Part Properties.
If you need more details, pictures or anything to help resolve the issue, please ask.