Unable To Cast Value To Object

So, I’m creating an admin commands script, and I’m trying to make it so when a player states “/commands” or something, a notification will pop up showing the list of commands. I’m currently using a script in SSS to fire the event, and then in starter GUI that’s where it gets the OnClientEvent. Any suggestions?

SSS_CODE

elseif Message == "/help" or Message == "/commands" or Message == "/cmds" then
			
			
			local CommandsList = {
				"/kick [player] - Kicks a player.",
				"/ban [player] - Bans a player.",
				"/unban [player] - Unbans a player.",
				"/mute [player] - Mutes a player.",
				"/unmute [player] - Unmutes a player.",
				"/jumppower [number] - Changes your jump power to the number specified.",
				"/kill[player]- Kills the target",
				"/respawn[player]- Respawns the target",
				"/gameban[player][reason]- Bans the user from joining even when server restarts."
			}
			
			
			game.ReplicatedStorage.Notification:FireClient("COMMANDS",CommandsList)

STARTERGUI_SCRIPT_LOCAL

game.ReplicatedStorage.Notification.OnClientEvent:Connect(function()
	local startergui = game:GetService("StarterGui")
	startergui:SetCore("SendNotification", {
		Title = "NOTIFICATION",
		Text = ""
	})
end)
1 Like

Well your issue in the server script is that you need to mention a client (player instance) in the first argument here Like: game.ReplicatedStorage.Notification:FireClient(Client, "COMMANDS",CommandsList) to send it to the client

2 Likes

image
That ended up sending a notification; however, the notification doesn’t have what I wanted on it.
It doesn’t have the title and the list of commands. ("COMMANDS", CommandsList) is what I want in the notification. COMMANDS being title, and then CommandsList being commands.

Then add some Variables to the function!

game.ReplicatedStorage.Notification.OnClientEvent:Connect(function(Title, ListOfCommands)
	local startergui = game:GetService("StarterGui")
	startergui:SetCore("SendNotification", {
		Title = "NOTIFICATION",
		Text = ""
	})
end)

Title will be the word commands, and ListOfCommands, will be the list of Commands when the remote event is fired.

1 Like

Here’s the thing, I’m using the notification thing for multiple commands to show errors and what not.

So…? I’m confused what your requesting or trying to do

It’s hard to explain. I want it so game.ReplicatedStorage.Notification:FireClient("COMMANDS",CommandsList) shows what I would like on the notification; however, I am unsure on how to do that.

I need you to explain more. Can you provide an example what would be on the notification. “When Player does this > This Shows up On the Notification”. I need as much info as I can get. Its unclear to me right now because I was given a lack of information when some info could be really helpful to what you want to excute

2 Issues here.

#1: You are not firing to a specific player, which you have to for it to accept. To fix this just update the Firing line. So:

game.ReplicatedStorage.Notification:FireClient(Player, "COMMANDS", CommandsList)

#2: Inside your local script, you are not putting anything into the Text variable which you need to do. So, something like this:

game.ReplicatedStorage.Notification.OnClientEvent:Connect(function(Type, CommandsList)
	local startergui = game:GetService("StarterGui")
        local text = ""
        if Type == "COMMANDS" then
            for _, command in pairs(commands) do
                   text = text .. "\n"..command
             end
        end

	startergui:SetCore("SendNotification", {
		Title = "NOTIFICATION",
		Text = text
	})
end)

Hopefully this helps! Here is the documentation for what I used.

RemoteEvents
For Loops

1 Like

Aside from the commands one:

Say I used the “/gameban” command, but I didn’t put the players name in correctly.

I’d get the notification telling me “Invalid Player Name”

Another one would be

If I did ban the player correctly
Notification: [Name] was banned.

image
I’m getting an error there.

Change “commands” to “Commands”

You will want to go to that command itself and do something like:

--Player Name is the Name of the player given in the command
if game.Players:FindFirstChild(PlayerName) then 
--Run Code to do command 
else 
`game.ReplicatedStorage.Notification:FireClient(Client, "COMMANDS", "Player is Invalid")`
end

This is a rough example of what you can do

image
Still the same.

Sorry, “Commands” with “CommandsList”.

If you don’t know this though based on the context I highly recommend you read the documentation to understand errors like this.

This has ended up working, thankfully. Still some errors though that I’ll try to get resolved.

Alright. What you can do is place my answer as the solution, then create a new thread addressing the errors, along with BOTH scripts in their entirety.

Also pairs and ipairs are kinda deperated, Its not and is at the same time… If I remember correctly, Roblox wants users to start Using ’ for _, command in CommandsList do’ and just remove it. I myself find this hard to adapt to it too, and I doubt roblox would ever remove it, but yea. Just an intresting fact

1 Like

Alright, thanks! I never actually knew this, I should probably give another read to the documentation.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.