Gameover that roast player and offering a tip base on what kill them

As the title suggest I’m trying to make a Gameover screen that contain a Flavor text that basically use to callout player’s skill issue while doing so offering a tip of how to avoid being in the same situation

the idea of how this work is everytime the player recive a fatal blow, a remoteevent will pass on the information of the latest damage player recieve to the localscript

the localscript inside the gui will then change the text and tip corresponding to the Attack that player die to

well then I can just coding every type of damage that ever exist in my game in that same localscript and call it a day but I want to try and use modulescript
so I set up a modulescript that basically storing all the damage type along side the Flavor text and the tip which can be call to use later

local Cause_Of_Death = {
	Rock = {
		FlavorText = "Now that rock is sad, you monster",
		Tip = "watch where you step and drink some more milk"
	},
	Unknown = {
		FlavorText = "wait what... how did you die??",
		Tip = " ¯\_(ツ)_/¯ "
	}
}

return Cause_Of_Death

the problem is I still not fully understand how modulescrript work and I tried to fix the problem myself but I wouldn’t be here if it work please tell me what’s wrong with my script

Localscript
-- bunch of services
local storage = game:GetService("ReplicatedStorage")
local tween = game:GetService("TweenService")
local player = game:GetService("Players").LocalPlayer
local lighting = game:GetService("Lighting")

-- bunch of reference to the instance
local info = TweenInfo.new(2,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut)
local gui = script.Parent
local title = gui.Title
local tips = gui.tips
local reviveButton = gui.revive
local realTipButton = gui.actualTip
local ScreenEffect = gui.ScreenEffect
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

-- path to module
local DeadList = require(script.DeadList)

-- bunch of events
local deadEvent = storage.Events.COD
local reviveEvent = storage.Events.Revive

-- variables
local COD = "Unknown"
local CurrentFlavorText = ""
local CurrentTip = ""

deadEvent.OnClientEvent:Connect(function(CauseOfDeath : string) -- this will recive the Casue of death imformation fron the enemy that kill the player
	COD = CauseOfDeath
end)

local function TextUpdate() -- this right here doesn't work if you understand what I'm trying to do here
	for i, v in pairs(DeadList) do
		if v.Name == COD then
			CurrentFlavorText = v.FlavorText
			CurrentTip = v.Tip
			break
		end
	end
end

local function Blur() -- make the screen blur
	local blur = ScreenEffect.B:Clone()
	blur.Parent = lighting
	tween:Create(blur, TweenInfo.new(2), {Size = 15}):Play()
end

local function FadeScreen() -- flash the screen before start decreasing in brightness and increase contrast
	local Flash = ScreenEffect.F:Clone()
	Blur()
	tween:Create(Flash, TweenInfo.new(2), {Saturation = -1}):Play()
	tween:Create(Flash, TweenInfo.new(2), {Contrast = 1}):Play()
	Flash.Parent = lighting
	tween:Create(Flash, TweenInfo.new(.1), {Brightness = 1}):Play()
	task.wait(.2)
	tween:Create(Flash, TweenInfo.new(.1), {Brightness = 0}):Play()	
end

local function GameoverScreen() -- main function (I'm actually call Flavor Text a "TIP" and the actual "TIP" realtip please don't judge me)
	TextUpdate()
	gui.Enabled = true
	title.Visible = true
	title.TextTransparency = 1
	tween:Create(title, TweenInfo.new(3), {TextTransparency = 0}):Play()
	task.wait(2)
	tips.Visible = true
	tips.Text = CurrentFlavorText
	tips.Transparency = 1
	tween:Create(tips, TweenInfo.new(2), {TextTransparency = 0}):Play()
	task.wait(1.5)
	reviveButton.Visible = true
	reviveButton.TextTransparency = 1
	reviveButton.BackgroundTransparency = 1
	realTipButton.Visible = true
	realTipButton.TextTransparency = 1
	tween:Create(reviveButton, TweenInfo.new(1), {TextTransparency = 0}):Play()
	tween:Create(realTipButton, TweenInfo.new(1), {TextTransparency = 0}):Play()
	tween:Create(reviveButton, TweenInfo.new(1), {BackgroundTransparency = 0.8}):Play()
	task.wait(0.5)
	reviveButton.Interactable = true
	realTipButton.Interactable = true
end

reviveButton.MouseButton1Click:Connect(function() -- tell the server to loadcharacter and remove screen effect
	reviveEvent:FireServer()
	COD = "Unknown"
	for i,v in pairs(lighting:GetChildren()) do
		if v.Name == "B" or v.Name == "F" then
			v:Destroy()
		end
	end
end)

realTipButton.MouseButton1Click:Connect(function() -- reveal actual tip
	tips.Text = CurrentTip
end)

reviveButton.MouseEnter:Connect(function() -- make the button a bit bigger when mouse hover above
	reviveButton:TweenSize(UDim2.new(0.191,20,0.104,20), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 1,true)
end)

reviveButton.MouseLeave:Connect(function() -- do the opposite
	reviveButton:TweenSize(UDim2.new(0.191,0,0.104,0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 1,true)
end)

humanoid.Died:Connect(function() -- fire event 2 second after the player die
	task.delay(2, function()
		FadeScreen()
		GameoverScreen()
	end)
end)

task.spawn(function() -- this just make the revive button do a funny rotate side to side
	while task.wait() do
		local T1 = tween:Create(reviveButton, info, {Rotation = 3})
		T1:Play()
		T1.Completed:Wait()
		local T2 = tween:Create(reviveButton, info, {Rotation = -3})
		T2:Play()
		T2.Completed:Wait()
	end
end)

The showcase of how it should work (in the video I manually set the flavor text and tip. In the current script above both Flavor Text and Tip stay default which is empty and that’s the problem)

Alright, I found a solution for your problem. This is my module script:

local CODList = {
	CauseOfDeath = {
		[1] = {
			Name = "Rock",
			Flavor = "banana",
			Tip = "dont eat"
		},
		[2] = {
			Name = "Unknown",
			Flavor = "how did you die",
			Tip = "..."
		}
	}
}

return CODList

Basically, you need to put the name inside the table itself with the flavor and the tip. Next, you can refer to these strings inside your table as CODList["Name"] or CODList["Flavor"] (you name them in the module script). This is my for loop:

local module = require(script.ModuleScript)

for i, cause in pairs(module.CauseOfDeath) do
	if cause["Name"] == "Rock" then 					--- COD instead of "Rock"
		
		local flavor = cause["Flavor"]
		local tip = cause["Tip"]
		print(flavor, tip)
        break   --- this isnt really needed
	end
end

As you can see, the name is inside the cause itself with the other strings. Also make sure that all the strings are named exactly the same. ["Tip"] and ["tip"] will output an error. If you need more help or info, dont hesitate to reply.

2 Likes

Ok I see that my first module just complicate thing up by stacking a bunch of index which is probably why it getting confuse real quick for me. thanks to you I gain two more braincell today

local CODList = {
	Cause_Of_Death = {
		[1] = {
			["Name"] = "Rock",
			["Flavor"] = "Now that rock is sad, you monster",
			["Tip"] = "watch where you step and drink some more milk"
		},
		[2] = {
			["Name"] = "Unknown",
			["Flavor"] = "wait what... how did you die??",
			["Tip"] = "¯\_(ツ)_/¯"
		}
	}
}

return CODList

bullying rock is fun

Happy to help. You can mark my comment as a solution :slight_smile:

1 Like

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