So, as my question stated, how do I change this script to refer to the Gui without having to place the Gui in the Script to run?
function died (playerDied, random)
playerDied.Humanoid.Died:Connect(function()
script.ScreenGui:Clone().Parent = random.PlayerGui
local player = game:GetService("Players")
player.CharacterAutoLoads = false
end)
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Wait()
died(player.Character,player)
player.CharacterAdded:Connect(function(dead)
died(dead,player)
end)
end)
Yeah, the script is in ServerScriptService while the Gui is in StarterPlayer so I need the Gui in the StarterPlayer to show up since this script requires the Gui to be in the script.
This player.CharacterAdded function will never run the first time, because you’re yielding for your CharacterAdded:Wait() Event first, before detecting an added Character the next time
There’s a lot to change with this script here, but I won’t get into all the main details
If you wanna refer to the Gui, add more variables to your script & consider moving your script somewhere else, like ReplicatedStorage :L
local RS = game:GetService("ReplicatedStorage")
local Plrs = game:GetService("Players")
local ScreenGui = RS:WaitForChild("ScreenGui")
local function PlayerDied(Plr)
local PlrGui = Plr:WaitForChild("PlayerGui")
local UIClone = ScreenGui:Clone()
UIClone.Parent = PlrGui
Plrs.CharacterAutoLoads = false -- Keep in mind that this will toggle for EVERY player in the server
end
local function PlayerAdded(Plr)
Plr.CharacterAdded:Connect(function(Char)
local Hum = Char:WaitForChild("Humanoid")
Hum.Died:Connect(function()
PlayerDied(Plr)
end)
end)
end
Plrs.PlayerAdded:Connect(PlayerAdded)
Alright, that seemed to work, but it won’t run because this script is not working.
local Market = game:GetService("MarketplaceService")
Market.ProcessReciept = function(reciept)
if reciept.ProductId == 1306306067 then
local player = game.Players:GetPlayerByUserId(reciept.PlayerId)
player:LoadCharacter()
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
The whole idea is to give the player a Gui when they die so that they can pay to respawn at the last checkpoint or they just can reset to the start.