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

Can someone help me with my fighting system?

Asked by 1 year ago
Edited 1 year ago

WARNING!!!

If you get triggered by inefficient scripts i advise you to not view this one If you wish to help, then, you've been warned

Prepare for eye torture

--Variables

local parts = game.Workspace.Parts:GetChildren()
local Players = game:GetService("Players")
local Dummy = game.Workspace.Dummy
local DummyHumanoid = Dummy.Humanoid
local debounce = false
local player = Players.LocalPlayer
local Character = player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local FadeInFrame = script.Parent.Parent.FadeInUI.FadeInFrame

--Battle Loop

for i, v in pairs(parts) do
    v.Touched:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") then
            script.Parent.Parent.FadeInUI.Enabled = true

            for k = 1,100 do
                FadeInFrame.BackgroundTransparency -= 0.005
                wait(0.05)
                if FadeInFrame.BackgroundTransparency == 0 then
                    break
                end
            end
            script.Parent.Parent.FadeInUI.Enabled = false

            Humanoid.WalkSpeed = 0
            Humanoid.JumpPower = 0
            script.Parent.Enabled = true
            Character:FindFirstChild("HumanoidRootPart").CFrame = game.Workspace.TpPart.CFrame + Vector3.new(0,1,0)

            if script.Parent.Enabled == true then
                if script.Parent.AtkSelector.Punch.MouseButton1Click then
                    script.Parent.AtkSelector.Punch.MouseButton1Click:Connect(function()
                        if not debounce then
                            debounce = true
                            DummyHumanoid.Health = DummyHumanoid.Health - 25

                            local function typeText(text)
                                for i = 1, #text do
                                    script.Parent.DialogueLabel.Text = string.sub(text, 1, i)
                                    wait()
                                end
                                wait(3)
                                script.Parent.DialogueLabel.Text = ""
                            end


                            if DummyHumanoid.Health <= 0 then
                                typeText("You won!")
                                Humanoid.WalkSpeed = 16
                                Humanoid.JumpPower = 40
                                script.Parent.AtkSelector.Punch.Visible = false
                                script.Parent.AtkSelector.Kick.Visible = false
                                script.Parent.AtkSelector.Cancel.Visible = false
                                script.Parent.Enabled = false
                                DummyHumanoid.Health = 100
                            else
                                script.Parent.AtkSelector.Visible = false
                                script.Parent.MagicSelector.Visible = false
                                wait(1)                 

                                typeText("This is the core battle system")
                                typeText("Isn't this cool???")                      
                                typeText("No??")
                                typeText("Welp, I tried")
                                Humanoid.Health = Humanoid.Health - 10                  
                                wait(1)
                                script.Parent.AtkSelector.Visible = true
                                script.Parent.MagicSelector.Visible = true
                                debounce = false
                            end
                        end 
                    end)            
                end     
            end 
        end
    end)
end

If you actually managed to get through this cluster hell, congrats, you're a trooper. But now i need your help.

So, i want to create a battle system but i am as terrible at scripting as i am at life, even though i love scripting

So, let me explain all this you saw

I have a folder of parts in the workspace that when any of these parts are touched by the player, all of the script begins to work.

Everything goes swimmingly the first time, but when i try to re - enter the fight (since there will be multiple of them) some ... things happen

If you noticed, at the start of the script i have this

            for k = 1,100 do
                FadeInFrame.BackgroundTransparency -= 0.005
                wait(0.05)
                if FadeInFrame.BackgroundTransparency == 0 then
                    break
                end
            end
            script.Parent.Parent.FadeInUI.Enabled = false

This is a fade in frame, so when i touch any of the parts, the screen starts turning white and then the frame disappears as the player gets teleported in front of the Dummy for the fight to begin.

Well, the first time this worked amazingly, though the second time... well uhh...

It did not, well, sort of, the screen immediately turned white and after some seconds i was teleported to where i had to be.

I did not really bother with that, i said to myself "eh it's alright i will find some help with that" but that was not the only problem

When i get teleported to the fight after i've already won, i can't damage the dummy

Yep, you've heard me, the script flat out breaks there and i can't do anything about it.

If you know how to help me (without telling me "make your script more efficient", which wouldn't actually be a bad idea) I'd appreciate it.

Again, I'm sorry for all this hell i caused

0
"Wow this script is efficient!"... said no one ever lolmarios2647 46 — 1y

1 answer

Log in to vote
1
Answered by
blowup999 659 Moderation Voter
1 year ago

For the issue with the whiteness, add this above the for loop

FadeInFrame.BackgroundTransparency = 1

For the issue with not damaging the dummy, you have a line

if not debounce then

but then you later do:

if DummyHumanoid.Health <= 0 then
else
    debounce = false
end

So just change it so it says debounce = false in the top part of the if statement or set debounce = false after the end.

Also the script may not optimal, but adding all that text about the issue definitely makes up for most of it.

0
Wait i am confused about the 2nd problem. Could you show me a visual representation on how to do it? (basically the lines of the script i need). Thank you for the help you've given so far lolmarios2647 46 — 1y
0
The if statement has two cases the if and the else - in your else you undo the debounce which allows you to damage the dummy, but you never undo it in the if case. blowup999 659 — 1y
0
So if immediately prior to the 'else' you add debounce = false, it should work blowup999 659 — 1y
0
Thank you very much for the help, it really did work. You've made me go one step closer onto making my game. Thank you lolmarios2647 46 — 1y
Ad

Answer this question