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

How do I make the death from a punch be shown to other players?

Asked by 5 years ago
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:wait()
repeat wait() until plr.Character.Humanoid
local humanoid = plr.Character.Humanoid
local mouse = plr:GetMouse()
canhit = false
canswing = true
local debris = game:GetService("Debris")

mouse.KeyDown:connect(function(key)
    if key == "e" and canswing == true then 
        canswing = false
        canhit = true
        local hitting = Instance.new('Part', char)
        hitting.Transparency = 1
        hitting.Size = Vector3.new(2,2,2)
        hitting.Name = 'Part'
        hitting.Anchored = false
        hitting.CanCollide = false

        hitting.CFrame = char["HumanoidRootPart"].CFrame * CFrame.fromEulerAnglesXYZ(0, 0, 0)
        local weld = Instance.new('Weld', hitting)
        weld.C0 = char.HumanoidRootPart.CFrame:inverse() * hitting.CFrame
        weld.Part0 = char.HumanoidRootPart
        weld.Part1 = hitting
        hitting.Orientation = char.HumanoidRootPart.Orientation
        debris:AddItem(hitting,0.5)

        hitting.Touched:connect(function(hit)
            if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Humanoid.Health > 0 and  hit.Parent.Humanoid:FindFirstChild(char.Name) == nil then
                if hit.Parent.Humanoid:FindFirstChild(plr.Character.Name) == nil and canhit == true then
                    hit.Parent.Humanoid:TakeDamage(100)
                    local Tag = Instance.new("StringValue")
                    Tag.Name = char.Name
                    Tag.Parent = hit.Parent.Humanoid
                    Tag.Value = "Hit Indicator"
                    debris:AddItem(Tag, .2)
                    canhit = false
                end
            end
            end)
        local Punch = char.Humanoid:LoadAnimation(script.Punch)
        Punch:Play()
        canhit = true
        wait(1)
        canhit = false
        canswing = true
    end
end)

Basically when i kill someone with my punch it only shows for me and not them It's not because of Filtering Enabled (It might be) My friend said it was because of the variables but he said he can't help.

0
the "repeat wait() until plr.Character.Humanoid" is dumb, you can just use plr.Character:WaitForChild("Humanoid") which is the same thing oh and also you have to handle the other player's humanoid on the server by RemoteEvents (meaning don't try hurting someone else on the client) bhqpping 80 — 5y
0
no repeat wait until plr.Character.Humanoid is not dumb since it works better than WaitForChild, waitforchild only waits a few seconds and then it breaks so its better to use repeat wait since it wont do anything until humanoid is loaded in fully Gameplayer365247v2 1055 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

What's done in LocalScripts isn't replicated (unless the client owns the Network Ownership, like with the Character), so killing another player from a LocalScript will only be visible to the player to whom the LocalScript belongs.

Everything you need to be visible to other players and the server needs to be done on the Server, which you can communicate to from your LocalScript with RemoteEvents and RemoteFunctions.

Ad

Answer this question