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

Why does this Remote Event not fire?

I'm making a global chat system, and I have a remote event to send what the client needs to have on their screen. Here is my chat system. ServerScript:

local chat = game:GetService('DataStoreService'):GetDataStore('GlobalChat')

while wait(1) do
	local function Update()
		local a = chat:GetAsync(1)
		local b = chat:GetAsync(2)
		local c = chat:GetAsync(3)
		local d = chat:GetAsync(4)
		print('Found messages.'..
			a..
			b..
			c..
			d)
game:GetService('ReplicatedStorage'):WaitForChild('ChatHandler'):FireAllClients(a, b, c, d)
		--Since the line of code couldnt fit the screen, I had to remove the indents for it.
	end
	local success = false
	repeat
		local s, m = pcall(Update)
		if not s then
			warn('Could not get messages due to '..m..'. Trying again.')
		end
	until success
end

LocalScript:

game:GetService('ReplicatedStorage'):WaitForChild('ChatHandler').OnClientEvent:Connect(function(a, b, c, d)
	print([[Client recieved messages.]]..
		a..
		b..
		c..
		d)
	script.Parent[1].Text = a
	script.Parent[2].Text = b
	script.Parent[3].Text = c
	script.Parent[4].Text = d
end)

The client does not print anything, nor does the server give an error. The server script, however, prints all the messages. Also, if you can, how can I prevent game script timeout?

2 comments

0

check if u didnt accidently disabled them

0

Check my edited answer.

1 answer

✓ Accepted answer

The only solution I could offer based on the lack of information would be to replace

    script.Parent[1].Text = a
    script.Parent[2].Text = b
    script.Parent[3].Text = c
    script.Parent[4].Text = d

With:

    script.Parent["1"].Text = a
    script.Parent["2"].Text = b
    script.Parent["3"].Text = c
    script.Parent["4"].Text = d

In the LocalScript. I assumed that the [1],[2],[3], and [4] were the names of TextLabels. In that case, their name would need to be in a string like ["1"],["2"], etc.

If you have any other problems, be sure to comment and we can figure it out together.

--- EDIT:

Following up on my previous statement, here's some revised server side code:

local chat = game:GetService('DataStoreService'):GetDataStore('GlobalChat')

function Update()
	local a = chat:GetAsync(1)
	local b = chat:GetAsync(2)
	local c = chat:GetAsync(3)
	local d = chat:GetAsync(4)
	print('Found messages.'..
		a..
		b..
		c..
		d)
	game:GetService('ReplicatedStorage'):WaitForChild('ChatHandler'):FireAllClients(a, b, c, d)
	--Since the line of code couldnt fit the screen, I had to remove the indents for it.
end

while wait(1) do
    Update()
end

If this doesn't work, no idea what your problem could be.

4 comments

0

The event does not even run. I made a print statement before it, and it never ran.

0

Why would this work? The only thing you changed is remove the pcall.

0

Your original code didn't work on my testing place. This one did, I ask you at least try it.

0

Strange. It worked without a pcall. Thanks!

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