Script not detecting child of an explosion

Hi, this script isn’t working and I can’t figure out why. Basically it makes the camera shake if your camera is close enough to an explosion. This works, but I only want it to shake for certain explosions. A value is added and named “NoSHK” to indicate that the screen should not shake, however it is still shaking with these explosions for some reason!

game.Workspace.DescendantAdded:connect(function(Thing)

	if Thing.ClassName == "Explosion" and  Thing.Visible == true then
		if (Thing.Position - game.Workspace.CurrentCamera.CFrame.Position).magnitude < 85 then
			if not Thing:FindFirstChild("NoSHK") then
				camerashake(Thing) 
				end
		end
	end
end)

How are you addng the NoSHK value to the explosion?

another script, it’s an attack.

local explode = Instance.new("Explosion")
		local noshake = Instance.new("StringValue",explode)
		noshake.Name = "NoSHK"
		explode.DestroyJointRadiusPercent = 0
		explode.Parent = workspace
		explode.Position = char.Torso.Position
		explode.BlastRadius = 12
		explode.BlastPressure = 0

Is the first script a local script, or are they server scripts, or…?

I just tried to test it out using the two scripts provided, and it seems to be working correctly?

the explosion creator script is in a tool, and the second script is a localscript. both work fine so idk why the screen still shakes!

If you replace the StringValue NoSHK with an attribute, does it have any impact on the outcome?

i.e.

local explode = Instance.new("Explosion")
explode:SetAttribute("NoSHK", true)
explode.DestroyJointRadiusPercent = 0
explode.Parent = workspace
explode.Position = char.Torso.Position
explode.BlastRadius = 12
explode.BlastPressure = 0

and

game.Workspace.DescendantAdded:connect(function(Thing)
	if Thing.ClassName == "Explosion" and  Thing.Visible == true then
		if (Thing.Position - game.Workspace.CurrentCamera.CFrame.Position).magnitude < 85 then
			if not Thing:GetAttribute("NoSHK") then
				camerashake(Thing) 
				end
		end
	end
end)

here’s a video of the issue. The screen shouldn’t be shaking still! Also sadly the attribute didn’t work. I’m checking the explosion in workspace and the value is there

Just to check something - can you please comment out the camerashake(Thing) line in the code?
Does it stop the shaking entirely for all explosions, or do the explosions still cause shaking?

stops it entirely. That’s the function for the camera shaking. I think the issue may be that the value is added like a millisecond too late or something

We can test that hypothesis by adding task.wait() just before the Attribute check!

Hmm. didn’t seem to do anything. I even tried changing is to task.wait(0.1) and it didn’t work

If you add

print(Thing:GetAttributes()) 

before the check, what does it output?

it prints an empty table in the output, which makes so sense cause the attribute is added before it even gets parented to workspace

Can you please comment out the

explode.Parent = workspace

line briefly?

I want to ensure that it is the correct explosion that is being processed.

it is, In workspace the value is under the explosion.

So the shaking stops entirely when you comment out the line? (Make sure you do test this)

Ahh my mistake. The whole time I was editing a similar attack with an explosion. The reason it was still shaking was because I was not editing the attack I was testing. The attribute method worked fine!

I suspected that something must have been happening that wasn’t affected by the script changes you were making, hence why I had you test commenting out various lines xD

1 Like

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