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

Remote event not working as intended?

Hey there,

i have this script that is fired from the client when a Humanoid is Touched it fires the Event but does not deal damage?

Local Script:

local Player = game:GetService("Players").LocalPlayer
local rs = game:GetService("ReplicatedStorage")
local Damage = rs:WaitForChild("Damage")
local wep = script.Parent
local input = game:GetService("UserInputService")

local db = false
local cooldown = 5

input.InputBegan:Connect(function(input,isTyping)
	if isTyping then
		return
		elseif input.UserInputType == Enum.UserInputType.MouseButton1 then print("Clicked")
		if db == false then
			db = true
			wep.Log.Touched:connect(function(hit)
				if hit.Parent:FindFirstChild("Humanoid") ~= nil and db == true then
				db = false
				Damage:FireServer(hit)
				end
			end)
		end
	end
end)


Damage.OnClientEvent:Connect(function()
	wait(cooldown)
	db = false
end)

Script:

local rs = game:GetService("ReplicatedStorage")
local Damage = rs:WaitForChild("Damage")
local cooldown = .25
Damage.OnServerEvent:Connect(function(hit) print("Fired Server")
	if hit.Parent:FindFirstChild("Humanoid") ~= nil then hit.Parent:FindFirstChild("Humanoid"):TakeDamage(20)
	end
end)

Thank you!

2 answers

✓ Accepted answer

I'm pretty sure that you can't use the ".Touched" event in a local script. In your situation, I would make a boolvalue that is set to true whenever an event is fired (from clicking the mouse) and check whether this value is true whenever the log is touched and deal damage accordingly.

1 comment

0

Seems the best way to do it, However what ive written doesnt seem to do damage? Check below. Thanks,

Updated code =

Local Script:

local input = game:GetService("UserInputService")
local hurt = script.Parent.Hurt
local cooldown = 3

	input.InputBegan:Connect(function(input,isTyping)
	if isTyping then
		return
		elseif input.UserInputType == Enum.UserInputType.MouseButton1 then print("Clicked")
		hurt.Value = true
		wait(cooldown)
		hurt.Value = false
		end
	end)

Script:

local Player = game:GetService("Players").LocalPlayer
local rs = game:GetService("ReplicatedStorage")
local Damage = rs:WaitForChild("Damage")
local wep = script.Parent
local hurt = script.Parent.Hurt
local cooldown = 3

			
wep.Log.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") ~= nil and hurt.Value == true then print("Hit human") hit.Parent:FindFirstChild("Humanoid"):TakeDamage(20)
		end
	end)

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