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

I Made a damage script for a sword but it's working weird?

Asked by 4 years ago
Edited 4 years ago

I Made a sword for a game and made a local script inside the bladebarrier (Which is a part around the real blade) and i made a script in ServerScriptService and a remote event in replicated storage. Here is the code inside the local script

local event = game.ReplicatedStorage.DamagePLR --- DamagePLR is the remote event
local blade = script.Parent --- the blade barrier
local Damage = 5 --- damage
blade.Touched:Connect(function(hit)
    local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) 
        if player then 
            event:FireServer(hit, player.Name, Damage)
    end
end)

this is the script

local event = game.ReplicatedStorage.DamagePLR
local da = false ---- debounce 

event.OnServerEvent:Connect(function(plr, hit, plrName, dmg)
    if not da then
        da = true

            hit.Parent:FindFirstChild("Humanoid"):TakeDamage(dmg)
            print(plrName) 
                wait(0.5)
            da = false  

        print("Damage Taken!")
    end
end)

lets say the player who is holding the sword is player 1 the one getting hit is player 2.

So what is happening is that when player1 hits player2 player2 dies on player 1s screen but on player2s screen he is still alive. How can i fix that? Thanks.

0
It is a glitch, happened to me too qVoided 221 — 4y

1 answer

Log in to vote
0
Answered by
Geobloxia 251 Moderation Voter
4 years ago

Because you are using a local script, it is only local or shown to the player's screen and not the server. Change it to a regular script.

0
Yes that is it. Phyrixia 51 — 4y
0
so i need to use two normal scripts. Ok i will try that. Thanks GreenSubZeroGamesYT 26 — 4y
Ad

Answer this question