Sword RemoteEvent issue

I wanna make a sword with RemoteEvent that damages people when touched.

Everything works perfectly on the LocalScript but not in the Script and i couldn’t find any other solutions so i asked it here.
This is the code i wrote

Ignore the --(texthere) things
LocalScript:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")

script.Parent.Handle.Touched:Connect(function(hit)
				--local block = hit.Parent.Katana.Block
				if slice.IsPlaying then
					if script.Parent.Value.Value == 0 then
					--	if block.Value == 0 then
							print("works")
							remoteEvent:FireServer(print("serverfired"))
							                  script.Parent.Value.Value = 1
						--elseif block.Value == 1 then
											--	hit.Parent:FindFirstChild("Humanoid"):TakeDamage(0) 
							                  script.Parent.Value.Value = 1						
					end
					end
				

	
			end)

and this is the Script in ServerScriptService

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")

function onTouched(hit)
	print("counted")
					hit.Parent:FindFirstChild("Humanoid"):TakeDamage(15) 
end


remoteEvent.OnServerEvent:Connect(onTouched())

Any solutions please?

1 Like

I see 2 issues here, one this Fire Server Makes no sense, you cannot send a print:

--Change this
remoteEvent:FireServer(print("serverfired"))
--to
remoteEvent:FireServer(hit)

Second your receiving the variable wrong and not accounting for the first player variable

--Change this 
function onTouched(hit)
--to
function onTouched(plr,hit)

You also connected the event wrong, you don’t need the extra set of parenthesis, so it should be remoteEvent.OnServerEvent:Connect(onTouched). It’s also not a good idea to just allow people to fire an event and damage whoever they want, you need some sanity checks if you’re going to do hit detection on the client.

Also, is that all there is to the LocalScript? slice is undefined, and there are some other problems which @Wizard101fire90 mentioned.

Thanks Wizard101fire90 and Sean21307, It is solved now! I can’t pick 2 solutions at once :frowning: