Help with some code?!

Hi developers,

So I am trying to make an event that will fire when I click a button, and all I am getting is my warn function popping up, and the event is not playing? How can I fix this, is there anyone out there that can help me with this problem; Alternatively, I want the script to spawn black parts infinitely when the event is fired, and its no doing that, so I know my warn function is working, and the rest of the script isn’t.

Here is the code and the error:

local button = script.Parent
local click = script.Parent.ClickEvent
local SS = game:GetService(“ServerStorage”)
local fire = SS.Events.Event1:WaitForChild(“Event1Fire”)
local value = SS.Events.Event1:WaitForChild(“Bool”)
click.MouseClick:connect(function()

value.Value = true
wait(1)
if value.Value == true then
	fire:FireAllClients(fire)
	if fire:FireAllClients(fire) then
		print("Client has been fired!")
		while true do
			wait(1)
			local function newPart()
				local coolPart = Instance.new("Part")
				coolPart.Name = "JohnnyIsHere"
				coolPart.Parent = game.Workspace
				coolPart.Color = BrickColor.new("Black")
				coolPart.Position = Vector3.new(0, 10, 0)
			end
		end
	else 
		warn("Client cound not be fired!")
	end
end
wait(1)
value.Value = false

end)

Here is my explorer tab and error:

Error:

image

Explorer tab:

image

Thanks a lot people!

Have a great day!

Hi,

You can’t return a value from firing a remote event to all clients. See how remote events work here.

Pressing a button should fire the remote event from a localscript and what happens in the server (i.e, spawning bricks) should be handled in a serverside script. Make sure to use :FireServer() and .OnServerEvent()

Have a good day.

Psst, use task.wait() instead of wait() for better game performance.

2 Likes

Thanks you so much for this deatiled and helpful reply. I shall use it in the game.