RemoteEvent isn't working?

Hello, I am trying to call a remote event but it isn’t running, and I can’t figure out why. This is my code:

Remote Event Call:

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Player = Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()

function EnableScripts()
	Char.LookAtMouse.Enabled = true
	Char.Shoot.Enabled = true
	Char.FlyScript.Enabled = true
	
	Player.PlayerGui.Stats.PointsFolder.PointsLabel:WaitForChild("PointsGUIScript").Enabled = true
end

script.Parent.Activated:Connect(function()
	script.Parent.Parent.Enabled = false
	ReplicatedStorage.Values:WaitForChild("GameIsPlaying").Value = true
	
	EnableScripts()
	
	ReplicatedStorage.Events.Chickens:FireServer()
end)

Remote Event:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Chicken = ReplicatedStorage.Assets.Chicken

local Playing = ReplicatedStorage.Values.GameIsPlaying

function SpawnChicken()
	local ChickenClone = ReplicatedStorage.Assets.Chicken:Clone()
	ChickenClone.Parent = workspace
	
	local SpinScriptClone = ReplicatedStorage.Assets.Scripts.Spin:Clone()
	SpinScriptClone.Parent = ChickenClone
end

ReplicatedStorage.Events.Chickens.OnServerEvent:Connect(function()
	while Playing.Value == true do
		print("Loop Began")
		task.wait(math.random(2.5, 4))
		SpawnChicken()
		print("Chicken Spawned")
	end
end)

I tried printing, testing values, etc. I couldn’t get it to work.

1 Like

When using RemoteEvents you have to have player as an argument if using OnServerEvent like so:

ReplicatedStorage.Events.Chickens.OnServerEvent:Connect(function(player)
	while Playing.Value == true do
		print("Loop Began")
		task.wait(math.random(2.5, 4))
		SpawnChicken()
		print("Chicken Spawned")
	end
end)
1 Like

The code looks fine, if you have these checked:

  1. Are there any errors in the output?
  2. Ensure the scripts aren’t disabled, and not making a rookie mistake by parenting a local script to workspace or putting scripts in ReplicatedStorage (which won’t let scripts run)
  1. Make sure this works normally, by the way what is the script’s parent?
  1. Is this value actually true, or you just set it on the client which won’t change for the server?
  2. This may sound dumb but is the OnServerEvent script a server script?

You actually don’t, it’s just optional to have it to check who had fired the event

3 Likes
  1. The script’s parent is a ImageButton. It works as all the other functions work.

  2. Yep, it was the value. I only set it on the client. Thanks!

1 Like

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