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

Parameters in Remote Event not passing correctly?

Background: I'm making a Holo training facility for a group I'm in and this is part of it's commands. The command is to display a message (like admin scripts) on every player's screen Gives me this error: 15:48:29.964 - Unable to cast value to Object

The game has Experimental Mode off

Server Script:

game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(msg)
		if game.Players:FindFirstChild(player.Name):GetRankInGroup(3207228) > 14 then
			if msg:sub(1,3) == "/M " then
				local filteredText = game.Chat:FilterStringForBroadcast(msg:sub(4), player)
				
				game:GetService("ReplicatedStorage").Message:FireClient(filteredText)
		    end
	    end
    end)
end)

There's a Remote Event in Replicated Storage that the Server Script fires, and in return a local script in PlayerGui copies a pre made 'template' gui and changes the text and makes it visible.

Local Script in Player's PlayerGui

game:GetService("ReplicatedStorage").Message.OnClientEvent:connect(function(filteredText)
	local a = script.Parent:FindFirstChild("Template"):Clone()
	a.TextLabel.Text = player..": "..filteredText
	a.TextLabel.Visible = true
	wait(5)
	a:Remove()
end)

Any help would be appreciated.

1 comment

0

:Remove is deprecated, :connect is deprecated, you should know what to do since i said this a million times.

1 answer

✓ Accepted answer

first of all, if you want to send a message on everyone's screen, use :FireAllClients(filteredText) :FireClient() needs the player to send it to as the first argument. Also, you have to pass the player who chatted through the remoteevent.

game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(msg)
        if game.Players:FindFirstChild(player.Name):GetRankInGroup(3207228) > 14 then
            if msg:sub(1,3) == "/M " then
                local filteredText = game.Chat:FilterStringForBroadcast(msg:sub(4), player)

                game:GetService("ReplicatedStorage").Message:FireAllClients(player, filteredText)
            end
        end
    end)
end)

game:GetService("ReplicatedStorage").Message.OnClientEvent:connect(function(player, filteredText)
    local a = script.Parent:FindFirstChild("Template"):Clone()
    a.TextLabel.Text = player.Name..": "..filteredText -- here you were trying to change the text to a player, not a player's name.
    a.TextLabel.Visible = true
    wait(5)
    a:Destroy()
end)

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