Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

C4 Function just doesn't work... And it's so basic! Why???

So I'm making a C4 and everything works, EXCEPT for the detonation and re-equip, which I'm working on.

Anyway, I'm completely baffled at how this script actually ignores itself. I first used a variable called "Flipped" and it would equal false at the top of the script. That clearly wasn't working, so I tried putting a boolean value inside the script and it reacted the same way!! What do I do? Am I just making a stupid mistake without realizing it?

Here's the function:


--Top of script
Flipped = false

function Detonate()
	if not Flipped then
		--Right here would have the animation, which I'm still working on
		Tool.Handle.PlantA:Play()
		print(tostring(Flipped))
		Flipped = true
		print(tostring(Flipped))
	elseif Flipped then
		--Complex explosion... Could be the problem... But it keeps printing "false true, false true" and it's making the sound. But it never says "true false, true false"
		for i,v in pairs(C4Folder:GetChildren()) do
			if v.Name == Player.userId.."_C4" then
				v.Name = Player.userId.."_C4_DETONATE"
				v.C4Blink.BrickColor = BrickColor.new("Really red")
				v.C4Blink.Beep:Play()
				delay(v.C4Blink.Beep.TimeLength, function()
					local explode = Instance.new("Explosion", workspace)
					explode.BlastRadius = script.ExplodeRadius.Value
					explode.Position = v.C4.Position
					local sound = Instance.new("Sound", v.C4)
					sound.SoundId = "rbxassetid://142070127"
					sound.Volume = 1
					sound.Pitch = 1
					sound:Play()
					game.Debris:AddItem(v, 3)
					explode.Hit:connect(function(hit)
						local Hit_Player = game.Players:GetPlayerFromCharacter(Hit.Parent) or game.Players:GetPlayerFromCharacter(Hit.Parent.Parent)
						if Hit_Player == nil or not script.AntiTK.Value or (Hit_Player ~= nil and not (not Hit_Player.Neutral and Hit_Player.TeamColor == Player.TeamColor)) then
							local Humanoid = hit.Parent:FindFirstChild(human)
							if not Humanoid then --Not there...
								Humanoid = hit.Parent.Parent:FindFirstChild(human)
								if not Humanoid then --Didn't hit a gun? Maybe it didn't hit a character at all!
									return
								end
							end
							if Humanoid == nil or not Humanoid then
								return
							end
							for i,v in pairs(Humanoid:GetChildren()) do
								if v.Name == "creator" then
									if v.Value == Player then
										v:Destroy()
									end
								end
							end
							local c = Instance.new("ObjectValue")
							c.Name = "creator"
							c.Value = Player
							game.Debris:AddItem(c, 5)
							c.Parent = Humanoid
							delay(0, function()
								if hit then
									hit.Visible = true
									wait(script.ReloadTickSpeed.Value)
									hit.Visible = false
								end
							end)
						end
						if Hit_Player ~= nil and script.AntiTK.Value then
							if Hit_Player.TeamColor == Player.TeamColor then
								explode.BlastPressure = 0
							end
						end
					end)
				end)
			end
		end
		print(tostring(Flipped))
		Flipped = true
		print(tostring(Flipped))
	end
end

I've been constantly looking over this and just can't figure it out! Do I just need to redo this function? Or am I just being completely ignorant and not seeing the simple mistake right in front of me?

2 comments

0

I feel you, heh. This has happened to me several times this week and it's insane and confusing. I wonder if it's some ROBLOX update that's doing this? Certainly not, but something must be causing it.

0

And I mean, by no error of our own.

1 answer

well, an observation would be that you have an elseif with flipped = true when you have an if statement making it true

3 comments

0

you should probably remake it differently, not in that setup

0

when you put elseif, it is a counter to if. if its not flipped then you flip it. the script only chooses one argument or the other, not both, so since its choosing if first its gonna only run that.

0

Um... That's what I want it to do... You right click once, and it opens the cover on the button, then you right click again, and the C4's blow. If I had two separate if statements, it would instantly blow. I may just have to deal with no cover for now...

This discussion is preserved as it was. New answers, comments, and votes are closed.