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

Why won't the humanoid take ten damage?

Asked by 4 years ago
wait(.2)
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character.Humanoid
local RightArm = Character:WaitForChild("RightArm")

RightArm.Touched:Connect(function(hit)
    local hum = hit.Parent:findFirstChild("Humanoid")
    if hum and not Humanoid then
        hum:TakeDamage(10)
    end

end)
0
Next time I reccomend saying more than just the code itself. User#24928 0 — 4y

1 answer

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

Use Remote Events! Because your game has Filtering Enabled! The client cannot communicate server unless with the use of remote events. To use it go to ReplicatedStorage and add a remote event. Add a server script in ServerScriptService. And copy these lines.

At the local script

-- Local Script
wait(0.2)
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character.Humanoid
local RightArm = Character:WaitForChild("RightArm")
local RemoteEvent = game.ReplicatedStorage.RemoteEvent -- Defining the remote event at the ReplicatedStorage

RightArm.Touched:Connect(function(hit)
       local hum = hit.Parent:FindFirstChild("Humanoid")
       if hum and not Humanoid then
              RemoteEvent:FireServer(hum, 10)
       end
end)

At the server script

-- Server Script(Normal Script)
local RemoteEvent = game.ReplicatedStorage.RemoteEvent -- Defining the remote event at the ReplicatedStorage

RemoteEvent.OnServerEvent:Connect(function(plr, hum, dmg)
       hum:TakeDamage(dmg)
end)

I hope it helps!

Ad

Answer this question