Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My combat does no damage, how can I fix it?

Alright so I was learning how to play animations and deal damage so I began learning to do that through combat. I made a local script that plays my right and left punch animation (works)

wait(2)
local player = game.Players.LocalPlayer
local char = player.Character
local punched = 0
local mouse = player:GetMouse()
local RP = 0
local LP = 0
local tool = script.Parent
local RPAnim = char.Humanoid:LoadAnimation(script.Right)
local LPAnim = char.Humanoid:LoadAnimation(script.Left)
function punch ()
	if punched == 0 and RP == 0 then
		RPAnim:Play()
		script.RightPunch:FireServer()
		punched = 1 RP = 1
		wait(.5)
		punched = 0 
	elseif punched == 0 and LP == 0 and RP == 1 then
		LPAnim:Play()
		script.LeftPunch:FireServer()
		punched = 1 LP = 1 RP = 1
		wait(.5)
		punched = 0 LP = 0 RP = 0
		
	end
end

function Equipped (mouse)
	mouse.Button1Down:Connect(punch)
end

tool.Equipped:Connect(Equipped)

Yes I have 2 remote events that are inside the local script and are used in a later script as well. Then I made a damage script within the local script (Damage isn't being dealt) The script is disabled btw. However it becomes enabled by the script after this one.


local hit = 0

function Damage (Part)
	if Part.Parent:FindFirstChild("Humanoid") ~= nil and Part.Parent:FindFirstChild("ForceField")== nil and hit == 0 then
		Part.Parent.Humanoid.Health = Part.Parent.Humanoid.Health - 10
		hit = 1
	end
end

script.Parent.Touched:Connect(Damage)

And then another script inside the local script that connects the damage script to my local script and moves my damage script inside my characters right and left arm when I punch (works)

game:GetService("Debris")

script.Parent.RightPunch.OnServerEvent:Connect(function(player)
	local Damage = script.Parent.Damage:Clone()
	Damage.Disabled = false
	Damage.Parent = player.Character:FindFirstChild("Right Arm")
	game.Debris:AddItem(Damage, .5)
	
end)

script.Parent.LeftPunch.OnServerEvent:Connect(function(player)
	local Damage = script.Parent.Damage:Clone()
	Damage.Disabled = false
	Damage.Parent = player.Character:FindFirstChild("Left Arm")
	game.Debris:AddItem(Damage, .5)
	
end)

Once again, everything works perfectly (Animations play, damage script is cloned inside right and left arm once animations play) but, damage isn't being dealt. What am I doing wrong and why is it wrong?

1 answer

Hello, your problem is that a server script cannot acces a remote event that is inside the client and vice versa.

Solution: Put the remote events on replicated storage.

Hope this helps :)

4 comments

0

Mi ment: put the remote events inside replicated storage

0

Mi ment: put the remote events inside replicated storage

0

Hello Oficcer_F, sorry for late reply I was busy. The script was working fine even without me putting the remove events in replicated storage (not sure why). but it seems the reason I thought it didnt work was because I was using play solo to test. It didnt work in play solo but when I tested it in a server the damage was working against another player.

0

Ok, glad it worked! :)

This discussion is preserved as it was. New answers, comments, and votes are closed.