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

The Remote Event is not working?

So when I play the game and touch the part that should Fire the Remote Event nothing happens and there is no problems or anything in the output. I'm not sure what is happening, I tried searching but still no solution

-- Server Script

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then

		
		game:GetService("ReplicatedStorage"):FindFirstChild("DestroyArrow"):FireClient(game:GetService("Players"):GetPlayerFromCharacter(hit.Parent))

	end
end)

-- ================================================================

-- Local Script

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

end)


2 comments

0

where did u put the local script

0

the script has to be a child of the part to work.

1 answer

✓ Accepted answer

Edit: You're destroying the script before you do what the RemoteEvent is intended to do, I would destroy the script's parent when complete. I use assertions, they return errors if they fail. If you find it in the output don't worry about it.

You should use the methods that Roblox has provided in their API Reference.

-------------------
--[[ Server Script ]]

local Players: Players = game:GetService("Players")
local ReplicatedStorage: ReplicatedStorage = game:GetService("ReplicatedStorage");
local RemoteEvent: RemoteEvent = ReplicatedStorage:WaitForChild("DestroyArrow");

script:FindFirstAncestorWhichIsA("BasePart").Touched:Connect(function(BasePart: BasePart)
	local Character: Model = BasePart:FindFirstAncestorWhichIsA("Model"); assert(Character);
	local Humanoid: Humanoid = Character:FindFirstChildWhichIsA("Humanoid"); assert(Humanoid);
	local Player: Player = Players:GetPlayerFromCharacter(Character); assert(Player);

	return RemoteEvent:FireClient(Player);
end)
-------------------
--[[ LocalScript ]]

local ReplicatedStorage: ReplicatedStorage = game:GetService("ReplicatedStorage");
local RemoteEvent: RemoteEvent = ReplicatedStorage:WaitForChild("DestroyArrow");

RemoteEvent.OnClientEvent:Connect(function()
	workspace:WaitForChild("Spawn", math.huge):WaitForChild("Arrow", math.huge):Destroy()
	script:Destroy()
end)

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