#Help

24 messages · Page 1 of 1 (latest)

gloomy slate
#

How do i make it so that i cant just swing the sword and then walk up to the player to do damage? I have no idea how this is happening pls help.

Local script in startercharacterscripts -

local debounce = true


local function Attack()
    local remoteevent = game.ReplicatedStorage.RemoteEvents.Combat.Attack

    if debounce == true then
        remoteevent:FireServer(equipped, debounce)
        
        debounce = false
    end
end

server script in startercharacterscripts -

local RemoteEvent = game.ReplicatedStorage.RemoteEvents.Combat.Attack

local connection -- Declare a variable to store the connection

local connection = RemoteEvent.OnServerEvent:Connect(function(player, equipped, debounce)

    local debounce = true
    print("passed2")
    local char = player.Character
    local humanoid = char:WaitForChild("Humanoid")
    local damageValue = 10 -- Set the base damage value
    local sword = char:WaitForChild("Sword"):FindFirstChild("Handle")

    local function onSwordTouched(part)
        if part.Parent and part.Parent:FindFirstChild("Humanoid") and equipped and debounce then

            local targetHumanoid = part.Parent.Humanoid

            if not part.Parent:FindFirstChild("Blocking").Value and not targetHumanoid:GetAttribute("RecentlyHit") then
                -- Player is not blocking, and the target hasn't been recently hit
                if debounce == true  then
                    print("yeuh")
                    debounce = false
                    targetHumanoid:TakeDamage(damageValue)
                    targetHumanoid:SetAttribute("RecentlyHit", true)
                    wait(0.5)
                    targetHumanoid:SetAttribute("RecentlyHit", false)
                
                elseif debounce == false then
                            
                    print("No")
                end
            end
        end
    end

    sword.Touched:Connect(onSwordTouched) -- Connect the event
end)

vague obsidian
#

qhat

gloomy slate
#

qhat

vague obsidian
#

can u send in normal video format

#

search mkv to mov or mp4

gloomy slate
#

oh my bad

#

gimme a sec

#

there

vague obsidian
#

add a checker instance thing with debris to make it auto delete itself in like 0.5-1 sec depending on what u want and on the if statement where u make it deal damage check if the checker exists whereever u put it and if it does then destroy it so it only hits once

gloomy slate
#

alr thank you imma try it out

#

it aint work

hoary wagonBOT
#

studio** You are now Level 1! **studio

gloomy slate
#

local RemoteEvent = game.ReplicatedStorage.RemoteEvents.Combat.Attack

local connection -- Declare a variable to store the connection

local connection = RemoteEvent.OnServerEvent:Connect(function(player, equipped, debounce)

local debounce = true
print("passed2")
local char = player.Character
local humanoid = char:WaitForChild("Humanoid")
local damageValue = 10 -- Set the base damage value
local sword = char:WaitForChild("Sword"):FindFirstChild("Handle")

local function onSwordTouched(part)
    if part.Parent and part.Parent:FindFirstChild("Humanoid") and equipped and debounce then
        local targetHumanoid = part.Parent.Humanoid
        
        local checker = Instance.new("Part")
        checker.Anchored = true
        checker.CanCollide = false
        checker.Size = Vector3.new(1, 1, 1)
        checker.Position = part.Position
        checker.Parent = game.Workspace 

        if not part.Parent:FindFirstChild("Blocking").Value and not targetHumanoid:GetAttribute("RecentlyHit") then
            -- Player is not blocking, and the target hasn't been recently hit
            if debounce == true  then
                print("yeuh")
                
                if checker then
                    checker:Destroy()
                    debounce = false
                    targetHumanoid:TakeDamage(damageValue)
                    targetHumanoid:SetAttribute("RecentlyHit", true)
                    wait(0.5)
                    targetHumanoid:SetAttribute("RecentlyHit", false)
                end

                
                local lifespan = 0.5
                wait(lifespan)
                checker:Destroy()

            elseif debounce == false then
                print("No")
            end
        end
    end
end

sword.Touched:Connect(onSwordTouched) -- Connect the event

end)

#

i prolly did it wrong

vague obsidian
#

game:GetService("Debris"):AddItem(checker, lifespan)

#

debris makes it so the code doesnt yield

gloomy slate
#

where do i put that?

vague obsidian
#

replace the 2 lines after the local lifespan = 0.5

#

or the place where u make the checker

gloomy slate
#

it still does damage if u swing before hand

vague obsidian
#

try adding the checker adding lines above the function and the debris also

gloomy slate
#

mouse.Button1Down:connect(function()
if equipped == true then

    if atkdebounce then -- check if debounce is enabled
        local remotevent = game.ReplicatedStorage.RemoteEvents.Sword.Animate
        remotevent:FireServer()
        print("passed") -- print something to see if it's running
        atkdebounce = false -- disable the debounce variable
        wait(0.15)
        Attack()
        wait(cooldown) -- wait for the amount of time the "cooldown" variable is
        debounce = true
        atkdebounce = true -- re-enable it()
    end
end

end)

this is where i call the attack function in the local script