Does anybody know why this affects ONLY ONE player?

Pretty simple question I have, why does this only work for one player? It may be me just being stupid but why does this ONLY affect one player?

	local radiussphere = Instance.new("Part", landmine)
					radiussphere.Anchored = true
					radiussphere.CanCollide = false
					radiussphere.Shape = Enum.PartType.Ball
					radiussphere.Size = Vector3.new(25,25,25)
					radiussphere.Position = landmine.Position
					radiussphere.Transparency = 1
					
					radiussphere.Touched:Connect(function(touched)
						if touched.Parent:FindFirstChild("Humanoid") then
							if touched.Name == "Torso" then
								local char = object.Parent
								gib_bomb(char)
							end
						end
					end)

This isn’t the ENTIRE script but if you really need it I can edit the post.

Is this script client-side or server-side?

This is serversided, everything about the script works but it for some reason only detects one player being touched. And when it does it detects it multiple times.

Could you improve on the context of the script and add the rest of it? I can’t seem to find why others players wouln’t trigger Touched:Connect

Yes, this is normal, since each time the player is moving, he his touching the part in question, thus firing it.

1 Like

This is the entire script function gib_bomb(chr) was me trying to fix it but I don’t know how to really fix it.

Whenever a character is detected inside the sphere, it is suppose to fire

gibmodule.giblimb(chr, chr["Right Leg"], "Explosive", 80)
gibmodule.giblimb(chr, chr["Left Leg"], "Explosive", 80)

Basically removing the legs, but right now all it does is removes the legs of the person who touched it and fling them.

Script
local landmines = script.Parent:GetChildren()
local gibmodule = require(game:GetService("ServerStorage").Mediaman_Gibs)

local Players = game:GetService("Players")
local Characters = Players:GetPlayers()
local hit = {}

function fling(source)
	local vf = Instance.new("VectorForce", source)
	local at = Instance.new("Attachment", source)
	vf.Force = Vector3.new(math.random(5000,8000),8500,math.random(5000,8000))
	vf.Attachment0 = at
	wait(.2)
	vf:Destroy()
	at:Destroy()
end

function gib_bomb(chr)
	if chr and not table.find(hit, chr) then
		table.insert(hit, chr)
		fling(chr.PrimaryPart)
		gibmodule.giblimb(chr, chr["Right Leg"], "Explosive", 80)
		gibmodule.giblimb(chr, chr["Left Leg"], "Explosive", 80)
	end
	
	repeat
		wait(.1)
	until chr:FindFirstChildOfClass("Humanoid").Health <= 0
	table.remove(hit, chr)
end

for _, landmine in pairs(landmines) do
	if landmine.Name == "Landmine" or landmine.Name == "AntiTankLandmine" then
		local debounce = false
		local effects = game:GetService("ServerStorage"):WaitForChild("Explosive_Effects")
		
		for _, effect in pairs(effects:GetChildren()) do
			if effect:IsA("ParticleEmitter") then
				local new = effect:Clone()
				new.Parent = landmine
			end
		end
		
		landmine:WaitForChild("Trigger").Touched:Connect(function(object)
			if object.Parent:FindFirstChild("Humanoid") then
				if debounce == false then
					debounce = true
					
					local radiussphere = Instance.new("Part", landmine)
					radiussphere.Anchored = true
					radiussphere.CanCollide = false
					radiussphere.Shape = Enum.PartType.Ball
					radiussphere.Size = Vector3.new(25,25,25)
					radiussphere.Position = landmine.Position
					radiussphere.Transparency = 1
					
					radiussphere.Touched:Connect(function(touched)
						if touched.Parent:FindFirstChild("Humanoid") then
							if touched.Name == "Torso" then
								print("got")
								local char = object.Parent
								gib_bomb(char)
							end
						end
					end)
					
					for _, effect in pairs(landmine:GetChildren()) do
						if effect:IsA("ParticleEmitter") then
							effect:Emit(20)
						end
					end
					local sound = Instance.new("Sound", landmine)
					sound.PlayOnRemove = true
					sound.Volume = 1.2
					sound.RollOffMaxDistance = 250
					sound.SoundId = "rbxassetid://13404155709"
					landmine.Transparency = 1
					landmine.CanCollide = false
					sound:Destroy()
					wait(3.8)
					landmine:Destroy()
				end
			end
		end)
	end
end

I can’t seem to find why it isn’t working. :confused: Everything seem right to me, I can’t test anything on roblox studio right now.

1 Like

Do you have any idea how I could at least add a buffer so the player is not constantly firing a touched event?

And do you think it would be better to use raycasts?

Raycasts would certainly be better, however I never had to use raycasts on any of my projects so I can’t help with that.

Based on the roblox docs, you could try to use BasePart | Roblox Creator Documentation onTouch and onTouchEnded, store the player who already toutch the part, and remove them when they don’t anymore (onTouchEnded). Then you just verify if the user already touched the part or not.

2 Likes

Thank you a lot! I’d rather use raycasts I suppose as this seems to be a lot more annoying.

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