Remote Event not Firing?

Hi everyone,

To summarize, I want to make a game where players can place boards on the windows, but only if you have a board in your backpack. If you don’t have a board in your backpack, then a notice pops up saying that there are no boards in your inventory.

This script is inside the board that the player will try activate.

local integrity = script.Parent.Parent.Parent.Integrity
local ReplicatedStorage = game:GetService('ReplicatedStorage')


script.Parent.Triggered:Connect(function(player)
	
	if player.BoardValue.Value >= 1 then
		script.Parent.Parent.Transparency = 0
		script.Parent.Enabled = false
		integrity.Value = integrity.Value + 2
		
		if player.BoardValue.Value > 0 then
			player.BoardValue.Value = player.BoardValue.Value - 1
		end
		
	elseif player.BoardValue.Value == 0 then
		print('Yaya') -- print statement runs perfectly
		ReplicatedStorage.Announce:FireClient('Hello') -- this is the problem
	end

end)

Script inside ServerScript Service

-- runs announcements

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

local announce = ReplicatedStorage:WaitForChild('Announce')

function Announce(message)
	
		game.ReplicatedStorage.Announce:FireAllClients(message)

end

Local script to print message:

function setAnnouncer(message)

	print(message)

end
game.ReplicatedStorage.Announce.OnClientEvent:Connect(setAnnouncer)

OutPut:

If you need anymore information, please let me know. Thanks :slight_smile:.

script.Parent.Triggered:Connect(function(player)
	
	if player.BoardValue.Value >= 1 then
		script.Parent.Parent.Transparency = 0
		script.Parent.Enabled = false
		integrity.Value = integrity.Value + 2
		
		if player.BoardValue.Value > 0 then
			player.BoardValue.Value = player.BoardValue.Value - 1
		end
		
	elseif player.BoardValue.Value == 0 then
		print('Yaya') -- print statement runs perfectly
		ReplicatedStorage.Announce:FireClient(player) -- this is the problem
	end

end)

I think this should work. FireClient requires a client for it to be fired from so ‘player’ is the client

When you receive an error stating “cannot cast X to Y,” that means you’re trying to state data of one type is actually data of another type (searching “data casting” would do that bit of explanation more justice). In this case, you’re trying to pass a parameter of the incorrect datatype though a method. More specifically, you’re trying to pass 'Hello' (a string, recognized as a “value”), through the method FireClient() which takes a Player (an object) as the first parameter.

You made a very simple error. When you do FireClient, you forgot to add the player to fire to as the first parameter. The script thinks that the string is the player when it’s not.

2 Likes