Hello, I have made an intro in a localscript, in correct files, and it is in StarterGui, everything works perfectly, but when you die in the game, the intro repeats. Here is the script:
local player = game.Players.LocalPlayer local gui = script.Parent local frame = gui:WaitForChild('Background') local logo = frame:WaitForChild('Logo') local introran = player:WaitForChild('IntroRan') local message = logo:WaitForChild('Message') wait() if introran == true then frame.BackgroundTransparency = 1 logo.BackgroundTransparency = 1 logo.ImageTransparency = 1 message.BackgroundTransparency = 1 message.TextTransparency = 1 gui:Destroy() else wait(2) for i = 1,0,-0.1 do logo.ImageTransparency = i message.TextTransparency = i wait(0.1) end wait(5) for i = 0,1,0.1 do logo.ImageTransparency = i message.TextTransparency = i wait(0.1) end for i = 0,1,0.1 do frame.BackgroundTransparency = i wait(0.1) end end
I would appreciate it if I could have the answer as part of this script, but anything is appreciated, thanks!
Due to the object being in StarterGui, this means that the GUI will reload each time on respawn. In order to avoid this with your script, you're going to want to put the GUI inside of a script that would be located in ServerScriptService or Workspace, which is should look like this:
--ServerScriptService -- Script -- GuiObject that contains your local script.
In the script, you will want to have the code fire every time a player enters the server. You will want to use the PlayerAdded event and clone the GUI into the Player's PlayerGui once it loads. Follow the code:
game.Players.PlayerAdded:connect(function(Plr) --Connect the PlayerAdded event of the Players service. It will give you the object value of the player entering so we'll call it Plr. repeat wait() until Plr:FindFirstChild('PlayerGui') --We'll repeat the wait() function until the argument is true. FindFirstChild returns true when an object named PlayerGui is found so it will continue with the script. script.GuiObject:Clone().Parent = Plr.PlayerGui --Since we know PlayerGui exists, we'll get the GuiObject that we have in the script, clone it, then set its Parent to PlayerGui. --Once that is complete, you're pretty much done. end
Just for a warning, this script does not work in FilteringEnabled servers. FilteringEnabled servers do not allow for regular scripts to mess with the PlayerGui, so just keep that in mind.
Well, I can think of a few ways around this problem. One is to put the script into ReplicatedFirst. This is where I put my intro script in and shows how much time it will take before the game is loaded. Another is to go to the StarterGui and turn ResetPlayerGuiOnSpawn to false (keep in mind this will affect all Gui in the StarterGui). Another option is to put a bool value in the player with the local script and then check for it at the start of the script, like this:
player=game.Players.LocalPlayer check=player:FindFirstChild("yep") if not check then check=Instance.new("BoolValue", player) check.Name="yep" --Then do all your stuff end
However, using a LocalScript to make this happen could have a adverse affect with FilteringEnabled. It should work but if it doesn't, you could always use a RemoteFunction or RemoteEvent.
Another way to do it is to put the script in the StarterPlayer.StarterPlayerScripts, they don't reset on death. There are many ways to get around this problem but these are the ideas I could think of.