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

Tool kills the player? [Attempt at FE Damaging]

Asked by
Clorize 31
4 years ago

So this tool is supposed to kill any player it touches EXCEPT the player. I've even made it detect if a player is the same player that is holding tool. The issue that lies is that it's still killing the player!

LocalScript inside Tool:

local tool = script.Parent
local debounce = false
local equipsound = tool.Sounds.Equip
local slashsound = tool.Sounds.Slash
local killsound = tool.Sounds.Kill
local isActive = script.Parent:WaitForChild("Values").isActive
local replicatedstorage = game:GetService("ReplicatedStorage")
print("Loaded...")



tool.Equipped:Connect(function(Mouse)
        print("Loaded....")
        equipsound:Play()
        Mouse.Icon = "rbxasset://textures/GunCursor.png"
        local char = script.Parent.Parent
        local knifehold = char.Humanoid:LoadAnimation(script.Parent.Animations.KnifeHold)
        knifehold:Play()
        tool.Activated:Connect(function()
            if debounce == false then
                print("Loaded.....")
                isActive.Value = true
                debounce = true
                slashsound:Play()
                local chosenanim = math.random(1,3)
                print("Loaded......")
                local anim = script.Parent.Animations["Slash"..chosenanim]
                local slash1 = char.Humanoid:LoadAnimation(anim)
                slash1:Play()
                wait(0.5)
                isActive.Value = false
                debounce = false
            end
        end)
        tool.Unequipped:Connect(function()
            knifehold:Stop()
            Mouse.Icon = ""
        end)
end)

tool.Handle.Touched:Connect(function(hit)
    if hit and hit.Parent and hit.Parent:WaitForChild("Humanoid") then
        if hit.Parent.Humanoid.Health > 0 then
            if hit.Parent ~= game.Players.LocalPlayer.Character and hit.Parent.Parent ~= game.Players.LocalPlayer.Character then
                replicatedstorage.KillEvent:FireServer(hit.Parent)
                killsound:Play()
            end
        end
    end
end)

ServerScript inside Tool:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local KillEvent = ReplicatedStorage:WaitForChild("KillEvent")

KillEvent.OnServerEvent:Connect(function(player)
    local plr = game.Workspace[player.Name]
    plr.Humanoid:TakeDamage(100)
end)

1 answer

Log in to vote
0
Answered by
Mayk728 855 Moderation Voter
4 years ago
Edited 4 years ago

it's because on the server script, you're asking it to kill the player who fired the event. The first argument in .OnServerEvent is always the player sending the request. the second argument is what the player is firing.

your ServerScript, fixed.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local KillEvent = ReplicatedStorage:WaitForChild("KillEvent")

KillEvent.OnServerEvent:Connect(function(player,arg1)
    local plr = game.Workspace:FindFirstChild(arg1.Name)
    if plr and plr:FindFirstChild('Humanoid') then
        plr.Humanoid:TakeDamage(100)
    end
end)
0
thanks, but does this mean i have to edit my localscript to say ":FireServer(player,argument)" Clorize 31 — 4y
0
nope. when the server gets the request, the first argument is the player. the second argument from the server is the first argument the client fired. Mayk728 855 — 4y
Ad

Answer this question