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)
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?
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
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?
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!