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

Why can't I cast value to Object?

I'm working on a quest system that I want to be as modular as possible. (I've somewhat succeeded in that) I've run into an error when I want to complete the quest. The end result is to get the client to change the text of a TextLabel upon completing a quest.

I

What I'm trying to do is FireClient inside of a ServerScript, but it's not letting me. I know there are other ways to get this done, but I kinda want to use RemoteObjects (just for the halibut)

Here's my code. The main problems are on:

Lines 48 on Server-side and Lines 60-62 on Client-side

The end result is to get the client to change the text of a TextLabel when a quest is completed.

Server-side code:

event.OnServerEvent:connect(function( ... )
	local tuple = { ... }
	local player = tuple[1]
	local pStats = RPGLib.getPlayerStats(player)
	local questID = pStats["QST"].Value
	local questIDs = {"testquest"}
	
	if tuple[4] == "Accept" then
		print("made it to accept")
		if questID == tuple[2] then
			if questID == questIDs[1] and tuple[3] == "Mobs" then
				print("made it to quest1")
				local questInfo = pStats["QINF"]
				
				local type = questInfo:FindFirstChild("Type")
				type.Value = "Mobs"
				
				local mobsObjective = questInfo:FindFirstChild("MobsObjective")
				mobsObjective.Value = 5
				
				local mobsCurrent = questInfo:FindFirstChild("MobsCurrent")			
				
				
				local mobsCompleted = questInfo:FindFirstChild("MobsCompleted")
				local activeQuest = pStats["AQST"]
				activeQuest.Value = true
				while activeQuest.Value == true and mobsCompleted.Value == false do
					wait()
					if mobsCurrent.Value == mobsObjective.Value then
						mobsCompleted.Value = true
						break
					else
						return
					end
				end		
			end
		end
	elseif tuple[4] == "Complete" then
		print("made it to quest complete attempt")
		if questID == tuple[2] then
			local player = tuple[1]
			if questID == questIDs[1] and tuple[3] == "Mobs" then
				print("made it to 'complete quest1'")
				local questInfo = pStats["QINF"]
				local QuestConfig = {1, 1, player} --Order of values: Difficulty, Level
				RPGLib.giveQuestReward(player, QuestConfig)

				event:FireClient("Finished testquest", player)
				
				local type = questInfo:FindFirstChild("Type")
				type.Value = " "
				
				local mobsObjective = questInfo:FindFirstChild("MobsObjective")
				mobsObjective.Value = 0
				
				local mobsCurrent = questInfo:FindFirstChild("MobsCurrent")			
				mobsCurrent.Value = 0
				
				local mobsCompleted = questInfo:FindFirstChild("MobsCompleted")
				local activeQuest = pStats["AQST"]
				activeQuest.Value = false
				
				local newQuestId = pStats["QST"]
				newQuestId.Value = " "
			end
		end
	end
end)

Client-side code:

local player = game.Players.LocalPlayer
local replicatedstorage = game:GetService("ReplicatedStorage")
local event = replicatedstorage:WaitForChild("RemoteEvent")
local mouse = player:GetMouse()

local gui = script.Parent
local chatprompt = gui:WaitForChild("ChatPrompt")
local questwindow = gui:WaitForChild("QuestWindow")

local NPCpic = questwindow:WaitForChild("NPCpic")
local NPCname = questwindow:WaitForChild("NPCname")
local QuestDesc = questwindow:WaitForChild("QuestDesc")
local questId = questwindow:WaitForChild("QuestID")
local questType = questwindow:WaitForChild("QuestType")

local accept = questwindow:WaitForChild("Accept")

local activeQuestWindow = false
local activeChatPrompt = false





event.OnClientEvent:connect(function( ... )
	local tuple = { ... }
	if tuple[1] == "PromptChat" then
		if tuple[8] == player.Name then
			chatprompt.Visible = true
			activeChatPrompt = true
		end
		if tuple[2] == "Quest" then
			mouse.KeyDown:connect(function(key)
				local name = tuple[3]
				local picid = tuple[4]
				local desc = tuple[5]
				local questid = tuple[6]
				local questtype = tuple[7]
				if activeChatPrompt == true and string.lower(key) == "e" then
					NPCname.Text = name
					NPCpic.Image = "rbxassetid://" .. tostring(picid)
					QuestDesc.Text = desc
					questId.Value = questid
					questType.Value = questtype
		
					questwindow.Visible = true
					
			
				end
			end)
			accept.MouseButton1Click:connect(function()
				local desc = tuple[9]
				QuestDesc.Text = desc
			end)
		end
		
	elseif tuple[1] == "CloseChatPrompt" then
		chatprompt.Visible = false
		activeChatPrompt = false
	elseif tuple[1] == "Finished testquest" and player.Name == tuple[2] then
		local desc = tuple[10]
		QuestDesc.Text = desc
	end
end)

2 comments

1

What is the exact output you are getting? At first glance the bug isn't obvious.

0

Only output I'm getting is "Unable to cast value to Object" line 48*

1 answer

✓ Accepted answer

According to the Wiki, the first parameter to FireClient is the player, and the remainder are the other arguments.


On line 48 of the server script, you call FireClient like this:

event:FireClient("Finished testquest", player)

This does not match the parameter order that FireClient expects. You need to pass player as the first parameter.


The error is referring to the fact that it cannot "cast" (meaning, "change types") the value "Finished testquest" into a ROBLOX object (a player).

1 comment

0

Mmkay, thanks. I'll look into it :D

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