local player = game:GetService("Players").LocalPlayer
local CanStab = true

local function IsNear()
    for i,v in pairs(game.Workspace:GetChildren())do
        print(v)
        if v:FindFirstChild("Humanoid")and v == not script.Parent.Parent.Humanoid then
            local Distance = (script.Parent.Parent.HumanoidRootPart.Position - v.HumanoidRootPart.Position).magnitude
            if Distance <= 30 then
                print("Positive")
                game.ReplicatedStorage.Stab:FireServer(player,v)
            else
                print("Negative")
            end
        end
    end
end







script.Parent.Activated:Connect(function()
    local Character = script.Parent.Parent
    local StabAnimation = Character.Humanoid:LoadAnimation(script.Parent.Stab)
    if CanStab == true then
        CanStab = false
        StabAnimation:Play()
        IsNear()
        wait(3)
        CanStab = true
    end
end)

also the server script

game.ReplicatedStorage.Stab.OnServerEvent:Connect(function(player,v)
    if v ~= player.Character.Humanoid then
        v.Character.Humanoid.Health = v.Character.Humanoid.Health - 10
        print(v.Name)
    end
end)

for some reason it can't seem to find the Dummy that is placed in the workspace and other players, anyone knows why?

also: https://gyazo.com/d2577126aa9457206832e682dc78a7dd

2 comments

0

You fired the player from the LocalScript, that's unnecessary since the first parameter of OnServerEvent is always the player, so what you should do game.ReplicatedStorage.Stab:FireServer(v)

0

true but it still doesn't solve my problem, but thanks.