I believe the server doesn't act as if the second quest is the current one since to it, it isn't. One of the two cases are possible in your script's logic as of now:
- You didn't change
questnum's value at all, neither on the server nor on the client.
- You change
questnum's value on the client, hence the server observes no change.
Here's the fixed script that adds 1 to questnum's value, you might want to put the line:
questnum.Value = questnum.Value + 1
in the if-then itself since as of now, the script will advance to quest 3 which you don't have a case for
local function onMouseClick(player)
local questnum = player:WaitForChild("Quests"):WaitForChild("questnumber")
print(questnum.Value)
if questnum.Value == 0 then
local Quest1 = game.ReplicatedStorage.Quest1
print("click1")
Quest1:FireClient(player)
elseif questnum.Value == 1 then
local Quest2 = game.ReplicatedStorage.Quest2
print("click2")
Quest2:FireClient(player)
end
questnum.Value = questnum.Value + 1
end
script.Parent.ClickDetector.MouseClick:Connect(onMouseClick)
On another note, here are some recommendations:
- A way to shorten your if-thens even further:
local function onMouseClick(player)
local questnum = player:WaitForChild("Quests"):WaitForChild("questnumber")
print(questnum.Value)
local remote = game.ReplicatedStorage:FindFirstChild("Quest"..questnum.Value)
remote:FireClient(player)
questnum.Value = questnum.Value + 1
end
script.Parent.ClickDetector.MouseClick:Connect(onMouseClick)
- Using a single remote for all quests since it can be extensive manual work to make a remote for each quest:
local remote = game.ReplicatedStorage:FindFirstChild("Quests")
local function onMouseClick(player)
local questnum = player:WaitForChild("Quests"):WaitForChild("questnumber")
remote:FireClient(player, questnum.Value + 1)
questnum.Value = questnum.Value + 1
end
script.Parent.ClickDetector.MouseClick:Connect(onMouseClick)
- Using
:Connect() instead of :connect(), :connect() is deprecated and should not be used.
That's it from me! Be sure to comment if you have any questions or I have made a mistake!
2 comments
I've been having a similar issue, I got no working help either.
Where do you change quesunum's value? All I can see is checking the value and firing the remote. In the off chance that the value is changed from the client, the server won't observe that change and will still run the first quest