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

How to give players damage with a RemoteFunction? [closed]

Asked by
TofuBytes 500 Moderation Voter
10 years ago

I formatted my weapon as a localscript and I'm trying to fix it to do damage to a player. When the knife is being swung it fires off to the RemoteFunction. This script which should do damage to the player, but it always prints nothing was hit when it does hit a player. Does anyone know what's wrong?

function game.ReplicatedStorage.Knife_Damage.OnServerInvoke(player)
        local knife = player.Character:WaitForChild("Knife")
        if knife.PlayDownStab == true then
                knife:WaitForChild('Handle').Touched:connect(function(hit)
                hit.Parent:findFirstChild('Humanoid').Health = hit.Parent:findFirstChild('Humanoid').Health - 50
                end)
        elseif knife.PlayStabPunch == true then
                knife:WaitForChild('Handle').Touched:connect(function(hit)
                hit.Parent:findFirstChild('Humanoid').Health = hit.Parent:findFirstChild('Humanoid').Health - 25
                end)
        elseif knife.PlayThrow == true then
                Workspace:WaitForChild('Handle').Touched:connect(function(hit)
                hit.Parent:findFirstChild('Humanoid').Health = hit.Parent:findFirstChild('Humanoid').Health - 100
                end)
        else
        print('No Player was hit')
        end
end
1
Try modifying this to use a RemoteEvent instead. It doesn't look you're returning anything, or that you specifically want the function that Invokes the server to wait until this function runs completely. Also, include the code that Invokes the server. adark 5487 — 10y
0
Yes, it's now working. Thank you! TofuBytes 500 — 10y

Locked by TofuBytes, Perci1, and Shawnyg

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?