Script help for a story game

I am making this for a story game, so I can fire a event that will give the players a win.

This is what I use as script to fire the other scripts.

GetWinEvent is red underlined. Check if it is defined correctly.

Yeah, I have problems with that, so I need someone who can help me with that

local dds = game:GetService("DataStoreService")
local dataStore = dds:GetDataStore("Values")
local GetWinEvent = game.ReplicatedStorage.GetWinEvent

--I'll just add this if you want it.
game.Players.PlayerAdded:Connect(function(plr)
	local stats = Instance.new("Folder")
	stats.Name = "leaderstats"
	stats.Parent = plr

	local stage = Instance.new("IntValue")
	wins.Name = "Wins"
	wins.Parent = stats

	local data = dataStore:GetAsync(plr.UserId)
	if data then
		print(data.Wins)
		for _,stat in pairs(stats:GetChildren()) do
			stat.Value = data[stat.Name]
		end
	else
		print(plr.Name .. " has no data")
	end
end)

GetWinEvent.OnClientEvent:Connect(function()

	local player = game.Players:GetPlayers()
	local character = player.Character
	
	dataStore:IncrementAsync(player.UserId, 1)
end)

Does this work for you? Try it.

wait where do I need to put this?

Make a script in ServerScriptService.

Okay, then I need to?

Qucik note, there is already a stats

  • ikepike3333

You copy the code and paste that into the script.

Optional

You can name the script “PlrHandler” or any name you want

the wins section in underline red, oof

Oops, replace the “stage” with “wins”.

Okay, I did it, but the GetWinevent is the underlined

What? Send me a screenshot. I’ll try to see.

Here it is its still red

Can you send me the variables you defined without sending the pictures?

Use the lua formatted text implemented into the dev forum
yourcodepic

‘’’
local CreateDialogueEvent = game.ReplicatedStorage.CreateDialogueEvent

local npc = game.Workspace.Max

local point1 = game.Workspace.Point1

local point2 = game.Workspace.Point2

local point3 = game.Workspace.Point3

local point4 = game.Workspace.Point4

local point5 = game.Workspace.Point5

local point6 = game.Workspace.Point6

– Other Useful Functions

local randomPlayerName

local randomPlayerId

local function getPlayerImage(player_id)

local content, isReady = game:GetService(“Players”):GetUserThumbnailAsync(player_id, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)

return content

end

local function getRandomPlayer()

local players = game.Players:getPlayers()

local number = math.random(1,#players)

local randomPlayer = players[number]

randomPlayerName = randomPlayer.Name

randomPlayerId = randomPlayer.UserId

end

– put your challenge functions here

local function challeng_example() – THIS IS JUST AN EXAMPLE! IT WON’T RUN

local Max_Image = “rbxassetid://4841171880”

CreateDialogueEvent:FireAllClients(Max_Image,“”)

wait(5)

getRandomPlayer()

CreateDialogueEvent:FireAllClients(getPlayerImage(randomPlayerId),“”)

end

local function challenge_intro()

local Max_Image = “rbxassetid://6790923696”

local Emma_Image = “rbxassetid://6791199409”

CreateDialogueEvent:FireAllClients(Max_Image,“Hello friends, today we will go on a city trip!”)

wait(5)

GetWinEvent:FireAllClients()

wait(5)

getRandomPlayer()

CreateDialogueEvent:FireAllClients(getPlayerImage(randomPlayerId),“Yay, we can go so much fun stuff in this city.”)

wait(5)

CreateDialogueEvent:FireAllClients(Max_Image,“Lets go to our hotel”)

wait(5)

npc.Humanoid:MoveTo(point1.Position)

npc.Humanoid.MoveToFinished:Wait()

npc.Humanoid:MoveTo(point2.Position)

npc.Humanoid.MoveToFinished:Wait()

npc.Humanoid:MoveTo(point3.Position)

npc.Humanoid.MoveToFinished:Wait()

npc.Humanoid:MoveTo(point4.Position)

npc.Humanoid.MoveToFinished:Wait()

CreateDialogueEvent:FireAllClients(Max_Image,“This is our hotel guys.”)

wait(5)

CreateDialogueEvent:FireAllClients(Max_Image,“Lets go inside”)

wait(5)

npc.Humanoid:MoveTo(point5.Position)

npc.Humanoid.MoveToFinished:Wait()

npc.Humanoid:MoveTo(point6.Position)

npc.Humanoid.MoveToFinished:Wait()

wait(3)

GetWinEvent:FireAllClients()

CreateDialogueEvent:FireAllClients(Emma_Image,“Welcome to emma’s hotel, how can I help you?”)

wait(5)

CreateDialogueEvent:FireAllClients(Max_Image,“We want to check in. We reserved a room for so much people.”)

wait(10)

CreateDialogueEvent:FireAllClients(Emma_Image,“One big room, okay sir, you have been checked in, I hope you enjoy your stay here, we will now clean your room.”)

wait(14)

CreateDialogueEvent:FireAllClients(Max_Image,“Okay, thank you miss, okay guys, lets explore the city. come back when it will get dark.”)

wait(15)

getRandomPlayer()

CreateDialogueEvent:FireAllClients(getPlayerImage(randomPlayerId),“Okay max, we promise we will come back before its dark.”)

wait(5)

end

local function challenge_1_Night1()

end

local function challenge_2_()

end

local function challenge_3_()

end

local function challenge_4_()

end

local function challenge_ending()

end

local function startGame() – This is your main function where we order the challenges

challenge_intro()

challenge_1_Night1()

challenge_2_()

challenge_3_()

challenge_4_()

challenge_ending()

end

wait(10) – waits 10 seconds

startGame() – runs the startGame functionprint(“Hello world!”)

‘’’

Sir, you forgot to put lua at the front of your “```” (no space)

local CreateDialogueEvent = game.ReplicatedStorage.CreateDialogueEvent

local npc = game.Workspace.Max

local point1 = game.Workspace.Point1

local point2 = game.Workspace.Point2

local point3 = game.Workspace.Point3

local point4 = game.Workspace.Point4

local point5 = game.Workspace.Point5

local point6 = game.Workspace.Point6

-- Other Useful Functions

local randomPlayerName

local randomPlayerId

local function getPlayerImage(player_id)

local content, isReady = game:GetService("Players"):GetUserThumbnailAsync(player_id, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)

return content

end

local function getRandomPlayer()

local players = game.Players:getPlayers()

local number = math.random(1,#players)

local randomPlayer = players[number]

randomPlayerName = randomPlayer.Name

randomPlayerId = randomPlayer.UserId

end

----------------------------------------

-- put your challenge functions here

local function challeng_example() -- THIS IS JUST AN EXAMPLE! IT WON'T RUN

local Max_Image = "rbxassetid://4841171880"

CreateDialogueEvent:FireAllClients(Max_Image,"")

wait(5)

getRandomPlayer()

CreateDialogueEvent:FireAllClients(getPlayerImage(randomPlayerId),"")

end

local function challenge_intro()

local Max_Image = "rbxassetid://6790923696"

local Emma_Image = "rbxassetid://6791199409"

CreateDialogueEvent:FireAllClients(Max_Image,"Hello friends, today we will go on a city trip!")

wait(5)

GetWinEvent:FireAllClients()

wait(5)

getRandomPlayer()

CreateDialogueEvent:FireAllClients(getPlayerImage(randomPlayerId),"Yay, we can go so much fun stuff in this city.")

wait(5)

CreateDialogueEvent:FireAllClients(Max_Image,"Lets go to our hotel")

wait(5)

npc.Humanoid:MoveTo(point1.Position)

npc.Humanoid.MoveToFinished:Wait()

npc.Humanoid:MoveTo(point2.Position)

npc.Humanoid.MoveToFinished:Wait()

npc.Humanoid:MoveTo(point3.Position)

npc.Humanoid.MoveToFinished:Wait()

npc.Humanoid:MoveTo(point4.Position)

npc.Humanoid.MoveToFinished:Wait()

CreateDialogueEvent:FireAllClients(Max_Image,"This is our hotel guys.")

wait(5)

CreateDialogueEvent:FireAllClients(Max_Image,"Lets go inside")

wait(5)

npc.Humanoid:MoveTo(point5.Position)

npc.Humanoid.MoveToFinished:Wait()

npc.Humanoid:MoveTo(point6.Position)

npc.Humanoid.MoveToFinished:Wait()

wait(3)

GetWinEvent:FireAllClients()

CreateDialogueEvent:FireAllClients(Emma_Image,"Welcome to emma's hotel, how can I help you?")

wait(5)

CreateDialogueEvent:FireAllClients(Max_Image,"We want to check in. We reserved a room for so much people.")

wait(10)

CreateDialogueEvent:FireAllClients(Emma_Image,"One big room, okay sir, you have been checked in, I hope you enjoy your stay here, we will now clean your room.")

wait(14)

CreateDialogueEvent:FireAllClients(Max_Image,"Okay, thank you miss, okay guys, lets explore the city. come back when it will get dark.")

wait(15)

getRandomPlayer()

CreateDialogueEvent:FireAllClients(getPlayerImage(randomPlayerId),"Okay max, we promise we will come back before its dark.")

wait(5)

end

local function challenge_1_Night1()

end

local function challenge_2_()

end

local function challenge_3_()

end

local function challenge_4_()

end

local function challenge_ending()

end

--------------------------------------------------

local function startGame() -- This is your main function where we order the challenges

challenge_intro()

challenge_1_Night1()

challenge_2_()

challenge_3_()

challenge_4_()

challenge_ending()

end

wait(10) -- waits 10 seconds

startGame() -- runs the startGame functionprint("Hello world!")
--Remote events
Local GetWinEvent = game.ReplicatedStorage.GetWinEvent

add this add the very top of the script.

--Our main npc

before local npc

--Points for npc

before local point1

This comments are made to avoid confusion when reading the code in the future.

Seems to work, but I have already a Stats.

Okay.
I will provide you a saving system for the wins incase you want.

Put this in your datastore script you just made earlier in serverscriptservice
--Put me before GetWinEvent
local function updateData(plr)
	local success, failed = pcall(function()
		dataStore:UpdateAsync(plr.UserId, function()
			local tbl = {}
			for _, i in pairs(plr.leaderstats:GetChildren()) do
				tbl[i.Name] = i.Value
			end
			return tbl
		end)
		print("Sucessfully saved in DataStore!")
	end)
	if failed then warn(failed); return end
end

game.Players.PlayerRemoving:Connect(function(plr)
	updateData(plr)
	print("Saving...")
end)

game:BindToClose(function()
	for _, i in pairs(game.Players:GetPlayers()) do
		updateData(i)
	end
end)

Please inform me if an error occurs from one of the codes I gave you.