Script isnt connecting

Im trying to make a flashbang script for a decoy, and it isnt detecting when its being touched after the humanoid dies, plz help!!!

script.Parent.Humanoid.Died:Wait()
script.Parent.HITSPHERE.Touched:Connect(function(otherPart: BasePart) 
	if otherPart:FindFirstChildOfClass("Humanoid") and otherPart.Parent ~= script.Parent then
		print(otherPart.Parent)
		game.ServerStorage.fx.Slowness.Parent = otherPart.Parent
	end
end)

local explosion = Instance.new("Explosion")
explosion.BlastPressure = 0
explosion.Parent = workspace
explosion.Position = script.Parent.HumanoidRootPart.Position

local light = Instance.new("PointLight")
light.Parent = script.Parent.Torso
light.Brightness = 300
light.Range = 5
wait(1)

light:Destroy()
1 Like

Assuming you want the script to be triggered when the player dies, there’s an easier way using Humanoid.Died:Connect()

something like this

local playerCharacter = script.Parent

local function onDied()
	local function onTouch(otherPart) 
		local otherCharacter = otherPart.Parent
		-- here you had written otherPart:FindFirstChildOfClass("Humanoid") which will always return false
		if otherCharacter then
			if otherCharacter:FindFirstChildOfClass("Humanoid") and otherCharacter ~= playerCharacter then
				local slowness = game:GetService("ServerStorage").fx.Slowness:Clone()
				slowness.Parent = otherCharacter
				-- if you don't clone it then you'd lose the original later on

				local explosion = Instance.new("Explosion")
				explosion.BlastPressure = 0
				explosion.Parent = workspace
				explosion.Position = script.Parent.HumanoidRootPart.Position

				local light = Instance.new("PointLight")
				light.Parent = script.Parent.Torso
				light.Brightness = 300
				light.Range = 5

				task.wait(1)
				light:Destroy()
				-- the rest of the sequence should be inside the function
			end
		end
	end
	playerCharacter.HITSPHERE.Touched:Once(onTouch)
end
playerCharacter.Humanoid.Died:Connect(onDied)

give this a try and it should work

Ok, ill try it! (characters so i can post)

This doesnt quite work. I inputted a print(otherCharacter) into it to check if it was connecting to it after a few times it failed, and it isnt printing.

Is the script meant to only work after the player dies?
From what was written, I gathered it was meant to explode someone else if they touched the HITSPHERE after you die.

If that’s not the case, I’d be more than happy to change it to work how you’d ask, I just need to know specifically how you want it to work

You are looking for a humanoid under a part.

otherPart:FindFirstChildOfClass("Humanoid")

Instead look for a humanoid under the part’s parent model.

otherPart.Parent:FindFirstChildOfClass("Humanoid")
1 Like

ohhhh
crap i didnt notice sorry

1 Like

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