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

The touch event is not firing in a local script?

script.Parent.Touched:Connect(function(hit)
	print("Touched")
	local d = hit.Parent:FindFirstChild("Humanoid")
	if d then
		script.Parent:Destroy()
		game.workspace.Spawn.Arrow:Destroy()
		print("Done")
	end
end)

so I tried the same code in a normal script and it worked but it's not working in a local script. what I'm trying to do is to make the parts get destroyed only for the client but it's not working. my goal is to just make the parts disappear for the client only whenever the player touches the part.

1 comment

0

use a remoteevent, because  script.Parent.Touched wont work on the client

1 answer

✓ Accepted answer

You can't use touched in a localscript

So we're gonna use a remote event

Server Script

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		
		script.Parent:Destroy()
		game:GetService("ReplicatedStorage"):FindFirstChild("DestroyArrow"):FireClient(game:GetService("Players"):GetPlayerFromCharacter(hit.Parent))
		
	end
end)

Local Script

game:GetService("ReplicatedStorage"):FindFirstChild("DestroyArrow").OnClientEvent:Connect(function()
	
	game.Workspace.Spawn.Arrow:Destroy()
	print("Done")
	
end)

1 comment

0

Thanks for the accepted answer

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