How would I make decisions into my game

Im not very good at scripting, but I want to make a gui that give a yes/no button, which I already made, to make a decision that affects the game, here is my current script for the game.

-- Clondus put notes like this

-- If you named your things the same as in the video then you don't have to rename things.

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local TeleportService = game:GetService("TeleportService")

local StarterGui = game:GetService("StarterGui")

local Players = game:GetService("Players")

-- No need to touch above

-- You inserted these in ReplicatedStorage

local FrameVisible = game.ReplicatedStorage:FindFirstChild("FrameVisible") -- BoolValue

local PlayerImage = game.ReplicatedStorage:FindFirstChild("SetPlayerImage") -- RemoteEvent

local PlayerName = game.ReplicatedStorage:FindFirstChild("PlayerName") -- StringValue

local NPCImage = game.ReplicatedStorage:FindFirstChild("NPCImage")

local Text = game.ReplicatedStorage:FindFirstChild("Text") -- StringValue

local CutscenesFolder = ReplicatedStorage:FindFirstChild("Cutscenes")

local LogFrameVisible = ReplicatedStorage:FindFirstChild("LogFrameVisible")

local LogsCollected = ReplicatedStorage:FindFirstChild("LogsCollected")

local LogsFolder = game.ServerStorage:FindFirstChild("Logs")

local NPCFolder = game.ServerStorage:FindFirstChild("NPC")

local sound = Instance.new("Sound", game.Workspace)

sound.SoundId = "rbxassetid://1911995155"

local NPC = game.Workspace:FindFirstChild("NPC")

local BNPC = game.Workspace:FindFirstChild("BNPC")

local Teleports = game.Workspace:FindFirstChild("Teleports")

local Sounds = game.Workspace:FindFirstChild("Sounds")

local CheckpointsA = game.Workspace:FindFirstChild("Checkpoints")

-- Blank variables, do not touch

local RandomPlayer

local Message

function TypeSound()

local Sound = Instance.new("Sound")

Sound.Parent = game.Workspace

Sound.Name = "TypeSound"

Sound.SoundId = "http://www.roblox.com/asset/?id=3333976425" -- You can change the typing sound if you like

Sound.PlaybackSpeed = 1

Sound.Volume = 0.5

Sound:Play()

coroutine.resume(coroutine.create(function()

wait(1)

Sound:Destroy()

end))

end

function SetText(word)

Message = word

for i = 1, #Message do

Text.Value = string.sub(Message, 1, i)

TypeSound()

wait(0.05) -- Time between each letter, 0.05 seconds is recommended. The smaller the faster.

end

end

function SetNPCText(word)

Message = word

for i = 1, #Message do

Text.Value = string.sub(Message, 1, i)

NPCImage:FireAllClients(NPCImage)

PlayerName.Value = "Jeffa" -- Put whatever you like here

TypeSound()

wait(0.05) -- Time between each letter, 0.05 seconds is recommended. The smaller the faster.

end

end

function SetBNPCText(word)

Message = word

for i = 1, #Message do

Text.Value = string.sub(Message, 1, i)

NPCImage:FireAllClients(NPCImage)

PlayerName.Value = "Cole" -- Put whatever you like here

TypeSound()

wait(0.05) -- Time between each letter, 0.05 seconds is recommended. The smaller the faster.

end

end

function SetRandomPlayerText(word)

Message = word

RandomPlayer = nil

wait()

RandomPlayer = Players:GetChildren()[math.random(1, #Players:GetChildren())]

PlayerName.Value = RandomPlayer.Name -- Sets the PlayerName to a random player's name

PlayerImage:FireAllClients(RandomPlayer) -- Sets the image to a random player's head

for i = 1, #Message do

Text.Value = string.sub(Message, 1, i)

TypeSound() -- Plays the typing sound

wait(0.05)

end

end

wait(15)

NPC.Humanoid:moveTo(CheckpointsA.Checkpoint1.Position)

NPC.Humanoid.MoveToFinished:Wait()

FrameVisible.Value = true

SetRandomPlayerText("Where are we...IM SCARED")

wait(2)

SetRandomPlayerText("It looks like we are in.. a.. cave?")

wait(2)

SetRandomPlayerText("Is Cole Ok? I think he might have got killed by Jeffa? Wheres Jeffa?")

wait(2)

SetRandomPlayerText("Maybe we should call the cops now?")

wait(2)

SetRandomPlayerText("I dont know... Maybe he'll come back for revenge?")

--for i, v in pairs(Players:GetChildren()) do

--script.BlackScreen:Clone().Parent = v

--TeleportService:Teleport(5794169018, v) -- Change "5794169018" to your game's ID

--end
5 Likes

So to clarify, you want the yes no button to be there at the start or appears after a specific event happens and they choose?

2 Likes

Yes, that is what I want to do.

You did not answer the question

See the or? This to let me know to make it visible from the start or only visible after an event has happened

this how you make gui button

Instance.new("ScreenGui", game.Players.LocalPlayer.PlayerGui").Name = "GUI"
local buton = Instance.new("TextButton", game.Players.LocalPlayer.PlayerGui.GUI)
buton.MouseButon1Click:Connect(function()
pirnt("Clicked")
end)

Y E S No

1 Like

First of all, it was already said to be more effective to split this into 2 lines, first one creating the object, second to parent it. Instead of having them in 1 line.

Next, you never resized the button so if he duplicated it, it would overlap. And it is also in offsets and scale.

Edit: Your script should have been

local gui = Instance.new("ScreenGui") 
gui.Parent = game.Players.LocalPlayer.PlayerGui

local button = Instance.new("TextButton")
button.Parent = gui
button.Text = "Text Of Button"  -- Change this to any text you want

You forgot ’ " ’ before ‘game.Players.LocalPlayer.PlayerGui’