Local Script in a GUI not firing a remote event

Hey,

So I am making a booking GUI to book tables etc, when the Submit button is clicked, it doesn’t fire the Remote Event in Replicated Storage, to test it, when it fires it is meant to print out “Fired”, but it doesn’t.

Server:

game.ReplicatedStorage.book.OnServerEvent:Connect(function()
	print("Fired")
end)

Local:

script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage:WaitForChild("book"):FireServer()
end)

Is the right code? I have tried most things and this normally works, but sometimes doesn’t.

1 Like

Try adding a :WaitForChild() here:

game.ReplicatedStorage:WaitForChild("book").OnServerEvent:Connect(function()
	print("Fired")
end)

If that doesn’t work, does the event fire at all? To check that add a print within the function in the Local Script.

1 Like

Doesn’t fire but it does print when I do print(“Hi”) when I press the button.

This is when I publish and play it in game. Also doesn’t work in Studio.

Are you sure your server script runs? Where is it parented? Does putting a print at the top of it work?

1 Like

Well, it runs the other functions and prints and just doesn’t fire the print inside in the event, if that makes sense.

The code is fine. You have a problem or an error somewhere else.

Sorry, the Remote Event is in Rep Storage, the event listener is in ServerScriptService and the local script that fires it is in the GUI

Mind providing a full script? A few lines isn’t enough to help find the issue.

If it isn’t key that you use MouseButton1Click, then might I suggest using GuiButton.Activated? Also, remove the click event and see if it prints if you fire it without any trigger.

Sure

local Trello = require(script.Parent.Trello.Main)
local MainBoard = Trello:GetBoardByName("Redacted")
local Bookings = MainBoard:GetListByName("Bookings")


function getbookings() -- This Works
	local bookings = Bookings:GetCards()
	for i,v in pairs (bookings) do
		local new = Instance.new("StringValue")
		new.Parent = game.ReplicatedStorage.Bookings
		new.Name = v:GetName()
		new.Value = v:GetDesc()
	end
end

print("Server Running") -- This Works

getbookings() -- This Works

while true do -- This Works
	wait(15)
	getbookings()
end


game:GetService("Players").PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(Message)
		if Message == "make" then
			local book = Trello.new("Card", "Test", Bookings)
			book:SetDesc("Card made by: "..Player.Name.."\nTime: Test\nTable: 1")
		end
	end)
end)

game.ReplicatedStorage:WaitForChild("book").OnServerEvent:Connect(function(p, plr, tablee, timee)
	print("Fired")
	local book = Trello.new("Card", plr, Bookings)
	book:SetDesc("Booking made by: "..p.Name.."\nTime: "..timee.."\nTable: "..tablee.."")
end)

while loops are blocking; they will yield the thread (script) until they complete the condition (this being true; meaning it will run forever).

Consider using courontines, a schedular, or move the while loop to the bottom of the code.

FWIW you also shouldn’t use Trello as a database; there’s a few other code smells but since it’s OT I’ll leave it to someone else to explain (feel free to DM me if you’d like more genera feedback on your code)

2 Likes