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)

2 comments
Any output errors? Also not the problem but you have come deprecated code, use :Connect. Where is th GUI script stored?
what is the output of the code???