RemoteEvent "unable to cast value to object" on Message System

Hello! I have a messaging system which basically is a gui system where you can “message” player alerts, objectives, or achievements In fact, it’s more of an achievement system as you see in minecraft.
In order to message the player, you have to fire a remote event, which contains 2 parameters: title and message. These are two string values which will change the 2 text labels in the message system.

So the problem is that whenever I fire the remote event, it says “unable to cast value to object” in the gui script where it displays everything.
Heres the code:

-- Variables
local Main = script.Parent
local TitleFrame = script.Parent["Title Frame"]
local Message = Main.MessageText
local Title = TitleFrame.MessageTitle

-- Function Set up
local function resetMessageProperties()
	Main.Visible = false
	-- Main Frame
	Main.Size = UDim2.new(0.35, 0,0.3, 0)
	Main.Position = UDim2.new(-0.015,0 , 0,0)
	Main.ZIndex = 1
	-- Title Frame
	TitleFrame.Size = UDim2.new(0.8,0 , 0.5,0)
	TitleFrame.Position = UDim2.new(0,0,0,0)
	TitleFrame.ZIndex = 2
	-- Message Text
	Message.Size = UDim2.new(0.9, 0,0.35, 0)
	Message.Position = UDim2.new(0.048,0,0.6,0)
	Message.Text = "message"
	TitleFrame.ZIndex = 2
	-- Title Text
	Title.Size = UDim2.new(0.9,0,0.85,0)
	Title.Position = UDim2.new(0.048, 0,0.061, 0)
	Title.Text = "Alert"
	TitleFrame.ZIndex = 3
end
local function playMessageAnimation(animtype)
	if animtype == 1 then
		Main.Position = UDim2.new(-0.078, 0,0, 0)
		Main:TweenPosition(UDim2.new(-0.015,0 , 0,0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, .1, false)
	else
		Main.Position = UDim2.new(-0.015,0 , 0,0)
		Main:TweenPosition(UDim2.new(-0.078, 0,0, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, .1, false)
	end
end

game.ReplicatedStorage.MessageClient.OnClientEvent:Connect(function(title, message)
	resetMessageProperties()
	Message.Text = message
	Title.Text = title
	Main.Visible = true
	playMessageAnimation(1)
	wait(2)
	playMessageAnimation(2)
	wait(0.1)
	resetMessageProperties()

end)

Thanks!

What does the server script look like

its in a proximity prompt script, so it alerts the player when you recieve a tool.
heres the function:

local function onPromptTriggered(promptObject, Player)
	if Player and Player.Character and promptObject == script.Parent then
		local Backpack = Player:WaitForChild("Backpack")
		local Tool = Storage:FindFirstChild(ToolName)
		if Tool and not Backpack:FindFirstChild(ToolName) then
			local ToolClone = Tool:Clone()
			ToolClone.Parent = Backpack
			game.ReplicatedStorage.MessageClient:FireClient("Test", "Test Message") -- here it is
		end
	end
end

The first argument in FireClient has to be the player you are sending the data to

local function onPromptTriggered(promptObject, Player)
	if Player and Player.Character and promptObject == script.Parent then
		local Backpack = Player:WaitForChild("Backpack")
		local Tool = Storage:FindFirstChild(ToolName)
		if Tool and not Backpack:FindFirstChild(ToolName) then
			local ToolClone = Tool:Clone()
			ToolClone.Parent = Backpack
			game.ReplicatedStorage.MessageClient:FireClient(game.Players.LocalPlayer,"Test", "Test Message") -- here it is
		end
	end
end

like this? if it is like this it still gives me the same error.

Sorry, I’m fairly new to scripting lol

Thats fine. If it’s a server script you cant access localplayer

try setting the first argument to Player

1 Like

K, thank you. One more thing, is there a reason it takes so long to fire the event? The prox script works instantly but the message takes 5 seconds to show up.

Try changing Player:WaitForChild(“Backpack”) to Player:FindFirstChild(“Backpack”) and see if that changes anything

1 Like