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

I think my script isn't working because values are in the wrong place, is this the case?

So im working on a 2d platforming game. Currently I have been working on enemies and have created this script:

local function onPartTouch(otherPart)
	local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
		if player then
			if script.Parent.Active.Value == true then
			print ("hi")
			script.Parent.Active.Value = false
			script.Parent.Parent.Killed.Suspended.Value = true
			if player.Character.PoweredUp.Value == true then
				player.PoweredUp.Value = false
				player.FullHealth = true
				print ("FullHealth True")
					end
			elseif player.Character.FullHealth.Value == true then
				player.FullHealth.Value = false
				player.HalfHealth.Value = true
				print("HalfHealth true")
					end
			elseif player.Character.HalfHealth == true then
				player.Head.CanCollide = false
				player.Torso.CanCollide = false
				print ("you oofed lol")
		end
		

			wait(3)
			script.Parent.Active.Value = true
			script.Parent.Parent.Killed.Suspended.Value = true
		
	end
script.Parent.Touched:Connect(onPartTouch)

The enemy is supposed to work like in a mario game. If you have a power up (PoweredUp) then you loose that but can still take two more hits before getting killed

so just some basic stuff about the script real quick.

I believe the part of the script that isn't working is after this part of it:

			if player.Character.PoweredUp.Value == true then
				player.PoweredUp.Value = false
				player.FullHealth = true
				print ("FullHealth True")
					end
			elseif player.Character.FullHealth.Value == true then
				player.FullHealth.Value = false
				player.HalfHealth.Value = true
				print("HalfHealth true")
					end
			elseif player.Character.HalfHealth == true then
				player.Head.CanCollide = false
				player.Torso.CanCollide = false
				print ("you oofed lol")

When I touch the part, it prints the "hi" but none of the other stuff. PoweredUp, FullHealth, and HalfHealth are all BoolValues. These are all in the player's character model. I think this is where I am going wrong, but I don't know for sure. Any help would be greatly appreciated.

Update: Script is working now, you guys are life savers. After going through and looking through some of the script more carefully I found that I had also dropped a few .Values, so that also was breaking it.

1 comment

0

if it doesn't error then they're all in the right place

1 answer

✓ Accepted answer

In the if statements you have player.Character, but after the ifs you only have player.

Try changing

if player.Character.PoweredUp.Value == true then
	player.PoweredUp.Value = false
	player.FullHealth = true
	print ("FullHealth True")
	end--Remove these ends
elseif player.Character.FullHealth.Value == true then
	player.FullHealth.Value = false
	player.HalfHealth.Value = true
	print("HalfHealth true")
	end --Remove these ends
elseif player.Character.HalfHealth == true then
	player.Head.CanCollide = false
	player.Torso.CanCollide = false
	print ("you oofed lol")
end

to

if player.Character.PoweredUp.Value == true then
	player.Character.PoweredUp.Value = false
	player.Character.FullHealth = true
	print ("FullHealth True")
elseif player.Character.FullHealth.Value == true then
	player.Character.FullHealth.Value = false
	player.Character.HalfHealth.Value = true
	print("HalfHealth true")
elseif player.Character.HalfHealth == true then
	player.Character.Head.CanCollide = false
	player.Character.Torso.CanCollide = false
	print ("you oofed lol")
end

1 comment

0

This worked!

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