Hi. I'm making a punch localscript but I need other players to see the damage I've dealt to the enemy NPCs. I've made a remote event but I don't know how to damage the player through it. It says "takedamage is not a part of player". How can I fix this? Thanks!

Here's the ServerStorageScript script:

local repstorage = game:GetService("ReplicatedStorage")
local remote = repstorage:WaitForChild("Remote")

remote.OnServerEvent:connect(function(humanoid, damagemarker)
	damagemarker()
end)

Here's the punch localscript:

local tool = script.Parent
local debounce = false
local swingsound = tool:WaitForChild("Swing")
local canattack = tool:WaitForChild("CanAttack")
local UIS = game:GetService('UserInputService')
local plr = game.Players.LocalPlayer
repeat wait() until plr.Character ~= nil
local char
local hum
local idle
local root = plr.Character:WaitForChild("HumanoidRootPart")
local debounce = false
local basiccombatdamage = 10
local repstorage = game:GetService("ReplicatedStorage")
local remote = repstorage:WaitForChild("Remote")

local function damagemarker()
    local bill = Instance.new("BillboardGui")
    bill.Parent = game.Workspace
    bill.Active = false
    bill.Adornee = char.Head
    bill.AlwaysOnTop = false
    bill.Enabled = true
    bill.Size = UDim2.new(1.2, 0, 1.2, 0)
    bill.StudsOffset = Vector3.new(math.random(-3, 3),math.random(-3, 3), math.random(-3, 3))
    local text = Instance.new("TextLabel", bill)
    text.BackgroundTransparency = 1
    text.Name = "TakeDamage"
    text.Size = UDim2.new(1.2, 0, 1.2, 0)
    text.Font = "Fantasy"
    text.FontSize = "Size48"
    text.Text = "10"
    text.TextColor3 = Color3.new(245, 255, 245)
    text.TextScaled = true
    text.TextStrokeColor3 = Color3.new(245, 245, 235)
    text.TextStrokeTransparency = 0
    text.TextWrapped = true
    for i = 1, 25 do
    wait(0.01)
    text.Position = text.Position - UDim2.new(0, 0, 0.04, 0)
    text.TextTransparency = text.TextTransparency + 0.04
    text.TextStrokeTransparency = text.TextStrokeTransparency + 0.04
    end
end
tool.Equipped:connect(function()
    char = char or plr.Character or plr.CharacterAdded:wait()
    hum = hum or char:WaitForChild("Humanoid")
    idle = idle or hum:LoadAnimation(script.Idle)
    idle:Play()
    idle.Looped = true
end)
tool.Activated:connect(function()
    if debounce == false then -- check if debounce is false
        local ray = Ray.new(root.CFrame.p, root.CFrame.lookVector * 4)
        local hit, hitposition = workspace:FindPartOnRay(ray, char)
        canattack.Value = true
	    local swing1animation = script.Parent.Parent.Humanoid:LoadAnimation(script.Punch1)
		local swing2animation = script.Parent.Parent.Humanoid:LoadAnimation(script.Punch2)
        local choose = math.random(1,2)
        if hit then
            local humanoid = hit.Parent:FindFirstChild("Humanoid")
            if not humanoid then
                humanoid = hit.Parent:FindFirstChild("Humanoid")
            end
	        if humanoid ~= nil and (root.Position - hitposition).magnitude <= 50 then
				local animspeed = swing1animation:AdjustSpeed(1000)
				swing2animation:AdjustSpeed(1000)
	            if choose == 1 then
	                debounce = true -- set debounce as true
	                swingsound:Play()
	                swing1animation:Play()
					wait(.1)
					remote:FireServer(damagemarker())
	                swingsound:Stop()
	                swing1animation:Stop()
	                debounce = false -- set debounce as false so the code can run again
	            elseif choose == 2 then
	                debounce = true -- set debounce as true
	                swingsound:Play()
	                swing2animation:Play()
					wait(.1)
					remote:FireServer(damagemarker())
	                swingsound:Stop()
	                swing2animation:Stop()
	                debounce = false -- set debounce as false so the code can run again
	            end
			end
		else
	            if choose == 1 then
	                debounce = true -- set debounce as true
	                local swing1animation = script.Parent.Parent.Humanoid:LoadAnimation(script.Punch1)
	                swingsound:Play()
	                swing1animation:Play()
	                wait(.6)
	                swingsound:Stop()
	                swing1animation:Stop()
	                debounce = false -- set debounce as false so the code can run again
	            elseif choose == 2 then
	                debounce = true -- set debounce as true
	                local swing2animation = script.Parent.Parent.Humanoid:LoadAnimation(script.Punch2)
	                swingsound:Play()
	                swing2animation:Play()
	                wait(.6)
	                swingsound:Stop()
	                swing2animation:Stop()
	                debounce = false -- set debounce as false so the code can run again
        		end
   			end
		end
end)
    tool.Deactivated:connect(function()
        canattack.Value = true
    end)

    tool.Unequipped:connect(function()
        idle:Stop()
    end)

4 comments

0

bruh i kinda have the same problem w my gun.

0

It will be more efficient to do things that you want other players to see or be affected on ServerScript instead of LocalScript so I suggest doing all the animation and damage stuff on a ServerScript

0

hm i dont know how that would work because its required for it to be in a localscript

0

Animations do not have to be run in local scripts, but it's recommended that they do (imo). However, you could do all of the damaging code in the server script. Also it's recommended to write damaging code inside of a server script because exploiters can abuse local scripts.