The script is supposed to give the player a GUI if they join the game and everytime they die. When they first join the game, they initially receive the GUI, but after they die, they no longer get the GUI again. This script works in solo mode, but does not work in an actual ROBLOX game. Can anyone think of any reasons this does not work? I can't understand why. I think it might be something wrong with the end part of the script but it looks right to me.
function PlayerJoined(Player) local Stats = Instance.new("IntValue") Stats.Name = "leaderstats" Stats.Parent = Player local Points = Instance.new("IntValue") Points.Name = "Points" Points.Value = 0 Points.Parent = Stats Powerups[Player] = {WalkSpeed = 16, AntiGrav = 0} Player.CharacterAdded:connect(function(Character) UpdatePowerUps(Player) Character.DescendantAdded:connect(function() UpdatePowerUps(Player) end) Character.DescendantRemoving:connect(function() UpdatePowerUps(Player) end) local Gui = Instance.new("ScreenGui") Gui.Name = "SpectateGui" local Button = Instance.new("TextButton") Button.BackgroundColor3 = Color3.new(0.1, 0.8, 0.9) Button.BackgroundTransparency = 0.2 Button.Position = UDim2.new(0, 0, 1, -90) Button.Size = UDim2.new(0, 350, 0, 20) Button.Text = ({[false] = "Spectating", [true] = "Playing"})[Playing[Player]] .. " (Click to switch)" Button.Parent = Gui Button.MouseButton1Click:connect(function() Playing[Player] = not Playing[Player] Button.Text = ({[false] = "Spectating", [true] = "Playing"})[Playing[Player]] .. " (Click to switch). It will affect you whenever a new round starts." end) local WalkspeedUp = Instance.new("TextButton") WalkspeedUp.BackgroundColor3 = Color3.new(0.9, 0.9, 0.9) WalkspeedUp.BackgroundTransparency = 0.2 WalkspeedUp.Position = UDim2.new(0, 0, 1, -110) WalkspeedUp.Size = UDim2.new(0, 155, 0, 20) WalkspeedUp.Text = "WalkSpeed +2 for 50 points (" .. Powerups[Player]["WalkSpeed"] .. ")" WalkspeedUp.Parent = Gui WalkspeedUp.MouseButton1Click:connect(function() if Powerups[Player]["WalkSpeed"] < 60 then if Points.Value >= 50 then Points.Value = Points.Value - 50 Powerups[Player]["WalkSpeed"] = Powerups[Player]["WalkSpeed"] + 2 WalkspeedUp.Text = "WalkSpeed +2 for 50 points (" .. Powerups[Player]["WalkSpeed"] .. ")" UpdatePowerUps(Player) end end if Powerups[Player]["WalkSpeed"] >= 75 then WalkspeedUp.Text = "WalkSpeed Maximum (75)" end end) local GravityUp = Instance.new("TextButton") GravityUp.BackgroundColor3 = Color3.new(0.9, 0.9, 0.9) GravityUp.BackgroundTransparency = 0.2 GravityUp.Position = UDim2.new(0, 0, 1, -130) GravityUp.Size = UDim2.new(0, 155, 0, 20) GravityUp.Text = "Gravity -4% for 50 points (" .. 100 - Powerups[Player]["AntiGrav"] .. "%)" GravityUp.Parent = Gui GravityUp.MouseButton1Click:connect(function() if Powerups[Player]["AntiGrav"] < 60 then if Points.Value >= 50 then Points.Value = Points.Value - 50 Powerups[Player]["AntiGrav"] = Powerups[Player]["AntiGrav"] + 4 GravityUp.Text = "Gravity -4% for 50 points (" .. 100 - Powerups[Player]["AntiGrav"] .. "%)" UpdatePowerUps(Player) end if Powerups[Player]["AntiGrav"] >= 60 then GravityUp.Text = "Gravity Minimum (40%)" end end end) local TutorialLabel = Instance.new("ImageLabel") TutorialLabel.BackgroundColor3 = Color3.new(1, 0.9, 0.2) TutorialLabel.BackgroundTransparency = 0.2 TutorialLabel.Position = UDim2.new(0, 0, 1, -268) TutorialLabel.Size = UDim2.new(0, 1, 0, 1) TutorialLabel.Parent = Gui local Index = 0 local PlayerGui = Player:FindFirstChild("PlayerGui") while not PlayerGui do wait() PlayerGui = Player:FindFirstChild("PlayerGui") end Gui.Parent = PlayerGui while PlayerGui.Parent do Index = Index + 1 if Index > #Tutorial then Index = 1 end TutorialLabel.Image = Tutorial[Index] wait(5) end end)
When I added your code into a script in a new place it said that you were missing an "end", but I assume you just forgot to copy it.
But I think the issue is that you didn't fire your "PlayerJoined()" function! Look at my code on line 34 on how do that, also replace "OnPlayerAdded" with your function "PlayerJoined"
Below is how I would've formatted it
local Players = game:GetService("Players") local ServerStorage = game:GetService("ServerStorage") -- Notice how I dont use ":FindFirstChild", because everything -- is based on when the Player and Character are added, so we -- can assume they're already loaded if that function is called. local TemplateGui = ServerStorage.TemplateGui -- I suggest pre-frabricating the GUI so we dont have to -- remake it everytime a new character is spawned. Later -- In the code we will just clone this and edit the values -- to be player specific. local function OnCharacterAdded(Character) local Player = Players:GetPlayerFromCharacter(Character) -- Getting the Player from the Character local ClonedGui = TemplateGui:Clone() ClonedGui.TextLabel.Text = Player.Name -- Do the Gui edits here... ClonedGui.Parent = Player.PlayerGui -- You did this in your script which is good because -- we edit the Gui before the player sees it. Preventing -- the player from seeing the default values. end local function OnPlayerAdded(Player) Player.CharacterAdded:Connect(OnCharacterAdded) -- Whenever the Player's Character spawns in we fire this end -- ":connect()" is depreciated use ":Connect()" Players.PlayerAdded:Connect(OnPlayerAdded)