When trying to pass through a string it goes nil?

Hi fellow developers I’m currently trying to pass a string thats from a table but when it goes to server side it breaks.

heres the activation:

	local Quests = {
		["Kill 5 Challengers"] = 5,
		["Become King"] = 1,
		["Kill 10 Challengers"] = 10,
		["Parry an attack"] = 1,
	}

	if not Quests[questName] then
		warn("No such quest: " .. tostring(questName))
		return
	end

	local goal = Quests[questName]

	-- Only fire this once
	local alreadyStarted = player:FindFirstChild("KillProgress") or player:FindFirstChild("Parry") or player:FindFirstChild("King")
	if not alreadyStarted then
		if questName == "Kill 5 Challengers" then
			game.ReplicatedStorage.StartedQuest:FireServer(true, tostring(questName))
		elseif questName == "Kill 10 Challengers" then
			game.ReplicatedStorage.StartedQuest:FireServer(true, tostring(questName))
		elseif questName == "Become King" then
			game.ReplicatedStorage.StartedQuest:FireServer(false, tostring(questName))
		elseif questName == "Parry an attack" then
			game.ReplicatedStorage.StartedQuest:FireServer(false, tostring(questName))
		end
	end

heres the serverside:

local ReplicatedStorage = game.ReplicatedStorage
local QuestStartEvent = ReplicatedStorage.StartedQuest

QuestStartEvent.OnServerEvent:Connect(function(Player,killingQuest,questName)
	Player.HasQuest.Value = true
	Player.CurrentQuest.Value = questName
	if killingQuest == true then
		local killNumber = Instance.new("IntValue",Player)
		killNumber.Name = "KillProgress"
	end
end)

please help me!

heres the error message

image

  • What is a questName variable on a client?
  • error tells that HasQuest is not a child of Player instance

It looks like you dont have instance named “HasQuest” under player

You have some bad code examples:

local killNumber = Instance.new("IntValue",Player)
		killNumber.Name = "KillProgress"

^ that would cause a “double replication” effect
Set parent after creating and configuring a variable instead so it gets replicated only once.
You sure that sending this request is safe to server?

1 Like

Sorry the questname is being fire from a script that randomly gives quests and it works I know that

is questName a string? If so, why are you running it through tostring() when using :FireServer? If it’s not, how is this check passing:?

if not Quests[questName] then
	warn("No such quest: " .. tostring(questName))
	return
end
2 Likes

print these 3 when firing the event, check if the player is a player, killingquest is a bool, and questname is a string, or it returns at least.

Is it a server script or a client sided script? As you would probably need a bindable event instead.

We might not have enough context.

1 Like

Currently not at my house will give more information when I get home

1 Like

Since I was getting that error I wanted to see wether or not I did to string it would do it

Here’s the quest giver script:

local textLabel = script.Parent:WaitForChild("SpeakingBox")
local player = game.Players.LocalPlayer

local QuestsModule = require(game.ReplicatedStorage.Quests)

local availableQuests = {
	"Kill 5 Challengers",
	"Become King",
	"Kill 10 Challengers",
	"Parry an attack",
}

local function typewriter(object, text, length)
	for i = 1, #text, 1 do
		object.Text = string.sub(text, 1, i)
		wait(length)
	end
end

while script.Parent.Parent.Enabled == false do
	wait()
end

if script.Parent.Parent.Enabled == true and player.HasQuest.Value == false then
	typewriter(textLabel, "Hey gladiator, I heard you're looking for some extra work in the arena...", 0.05)    
	-- Pick a random quest
	local randomIndex = math.random(1, #availableQuests)
	local randomQuest = availableQuests[randomIndex]
	wait(1)
	if randomQuest == "Kill 5 Challengers" then
		typewriter(textLabel, "Kill 5 other challengers and I'll give you some XP.", 0.05)
	elseif randomQuest == "Kill 10 Challengers" then
		typewriter(textLabel, "Kill 10 other challengers and I'll give you some XP.")
	elseif randomQuest == "Become King" then
		typewriter(textLabel, "Become the king of the gladiators once and I'll give you XP.")
	elseif randomQuest == "Parry an attack" then
		typewriter(textLabel, "Using the spear parry one player's attack.")
	end
	wait(1.5)
	game.ReplicatedStorage.StartedQuest:FireServer()
	script.Parent.Parent.Enabled = false
	QuestsModule.new(randomQuest,player)
end

this is a client sided script btw

In the ServerScript print(questName) for a check.

This looks odd.

if questName == "Kill 5 Challengers" then
	game.ReplicatedStorage.StartedQuest:FireServer(true, tostring(questName))

No need for tostring(questName) vs questName… clearly it’s a string.

Okay so I did it in the module script it gave the correct one, but when it printed in the serverscript it comes out as nil. When we call the event should I pass the quest name as the goal variable?

Nevermind I tried the goal variable where its Quests[questName] still didnt work :sob:

It turns out in my quest giving script at the bottom I was calling the event and it broke the entire script. Then the hasquest bool broke when trying to fire the events but all I had to do was specify its value. Thanks for your help!

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