I made working weapons, but the code only runs on one screen

I am trying to program weapons you can use in a game I made.

My code only runs on one client and doesn’t hurt them on their own screen. I have no idea how to fix it

I looked for solutions on dev forums, but only found some discussions about GUI glitches.

Here’s the code;

local plr = game.Players.LocalPlayer
local chr = plr.CharacterAdded:Wait()
local hum = chr:WaitForChild("Humanoid")
local item = script.Parent
local attacking = 0
local animation2 = script.Parent.Slice
local track2 = hum:LoadAnimation(animation2)
track2.Priority = "Action"
local handle = item.Handle
local sound1 = script.Parent.explosion
local sound2 = script.Parent["knife swing"]
local db = 0



item.Activated:Connect(function()
	if db == 0 then
		db = 1
		track2:Play()
		wait(2)
		sound2:Play()
		attacking = 1
		wait(2)
		db = 0
	end
end)
track2.Stopped:Connect(function()
	attacking = 0
end)

handle.Touched:Connect(function(hit)
	if hit.Parent:IsA("Model") and hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= plr.Name then
		if attacking == 1 then
			hit.Parent.Humanoid.Health = (hit.Parent.Humanoid.Health - 70)
			local explode = Instance.new("Explosion")
			explode.Parent = hit
			sound1:Play()
			attacking = 0
		end
	end
end)

Try killing the player on the server instead of the client

3 Likes

Should I send a message to a script inside of server script storage with the target’s humanoid?

yeah use a remote event for it

This is a very common issue with ROBLOX games. You need to change the Touched event to Touched:Connect(function(hit)–Insert Code here). This will allow it to work on all clients.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.