Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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.

0
if it doesn't error then they're all in the right place Fifkee 2017 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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
0
This worked! DiabloTheCat 40 — 4y
Ad

Answer this question