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

Roblox Error: Unable To Cast Value To Object?

So I am creating an admin command bar is one of the commands are: !warn . Now for this command to function, I have a remote event and a server and local script. Now I don't know if it's the remote event or something but I keep getting this error: Unable to cast "value" to object. Please help me find a solution!

Local Script: -- Yes, yes I know I shouldn't use the draggable thingy but whatever.

*Error is in local script, line 20

local frame = script.Parent

frame.Draggable = true
frame.Active = true
frame.Selectable = true

local Event = game:GetService("ReplicatedStorage")["Admin Events"].WE

script.Parent.Close.MouseButton1Click:Connect(function()
	script.Parent.Visible = false
end)

local MainFrame = script.Parent.MainFrame

MainFrame.Submit.MouseButton1Click:Connect(function()
	local target = MainFrame.Player.Text
	local reason = MainFrame.Reason.Text
	
	if target.Text 	~= "" then
		Event:FireClient(target,reason)
	end
end)

Server Script:

local File = game:GetService("ReplicatedStorage")
local FileName = "Admin Events"
local Object = File[FileName]["WE"]
local Admins = {"suspectshot108","SithVirtus","adam7adam"}

Object.OnServerEvent:Connect(function(player,target,reason)
	local msg = Instance.new("Message",workspace)
	local text = "[From:] "..player.." [Message]: "..reason
	for i = 1,#text do
		msg.Text = string.sub(text,1,i)
		wait(.07)
	end
	wait(3)
	msg:Remove()
end)

2 comments

0

um which line is the error on

0

Local Script, 20

1 answer

on line 20, you never specified which client to fire to on :FireClient(). you'd need to put the player you want to fire to inside the arguments. also :Remove() and the parent argument of Instance.new() is deprecated, use :Destroy() and set the parent last. im not sure if this is what you wanted, but if you parent a message to workspace, it'll replicate to all players. instead just set it to the player's character so only the player can view it i believe. Since your firing from the client USE :FireServer(), not :FireClient().

--client

frame.Draggable = true
frame.Active = true
frame.Selectable = true

local Event = game:GetService("ReplicatedStorage")["Admin Events"].WE

script.Parent.Close.MouseButton1Click:Connect(function()
    script.Parent.Visible = false
end)

local MainFrame = script.Parent.MainFrame

MainFrame.Submit.MouseButton1Click:Connect(function()
    local target = MainFrame.Player.Text
    local reason = MainFrame.Reason.Text

    if target.Text  ~= "" then
        Event:FireServer(target,reason)
    end
end)

| |

--server

local File = game:GetService("ReplicatedStorage")
local FileName = "Admin Events"
local Object = File[FileName]["WE"]
local Admins = {"suspectshot108","SithVirtus","adam7adam"}

Object.OnServerEvent:Connect(function(player,target,reason)
    local msg = Instance.new("Message")
    local text = "[From:] "..player.." [Message]: "..reason
	local player = game.Players:FindFirstChild(target)

if player then
	msg.Parent = player.Character

 	 for i = 1,#text do
      	 msg.Text = string.sub(text,1,i)
       	wait(.07)
   	end
    wait(3)
   msg:Destroy
end
	
end)

6 comments

0

I would like only one player to see the message, the target.

0

And I use :Remove() to destroy GUI objects. It just kinda stuck.

0

done

0

Does it show to the target only?

0

Messages are deprecated as well; switch to GuiObjects.

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