I need help with a problem I got with my game

Hello. I need some help with my game.
Basically with my game I need a script that when the player touches a block a UI covers there screen and teleport them to a different area in the game and move a (Sky) From (Sever Storage) to (Lighting) I have looked all over the internet I have watched similar tutorials that I fort would help but so far no luck.

I don’t need a script but its up to you if you want to provide one.
Any help is appreciated Thanks!

Steps:

  1. Listen for block touches, add a script into the block, and get the player that touched it.
script.Parent.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if not player then return end
end)
  1. Make the desired gui visible (in the PlayerGui not StarterGui)
local plrGUI = player.PlayerGui 
local gui = plrGUI.myGui
local frame = gui.Frame

frame.Visible = true
  1. The final script should be:
script.Parent.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if not player then return end
    local plrGUI = player.PlayerGui 
    local gui = plrGUI.myGui
    local frame = gui.Frame

    frame.Visible = true
end)

Note: you may need to change some paths

1 Like

Can I ask where the PlayerGUI is because its not showing on my screen.

PlayerGui is in the player. Upon join whatever you put in StarterGui during development gets cloned into the Players PlayerGui. If you want the player to see UI updates, you must update their PlayerGui not StarterGui

Thank you so much! It works and you have lifted away so much stress.
All I got to do now is make the player get teleported and the sky in (Sever Storage) gets moved to (lighting)

Do you have any ideas on how I would do this.

Btw I’m new to scripting so I don’t know much.

Hi, for this i need to make a question, do you want to change the sky for all the players or only for the player who touched the part?

For all the players as I think it would be easier as its going to be one per server.

Ohh it’s a game with only one player per server?

Uhh actually, i’m going to make a script for u with a script that will change the sky only for that player who touched the part because if you want to add multiplayer it would be easier :slightly_smiling_face:

Yep its going to be a story ending games and thanks.

Ok, i got it.

These are the scripts:

Script in the teleporter block:

local Goal = game.Workspace.Goal

local ChangeSkyEvent = game:GetService("ReplicatedStorage").ChangeSkyEvent

script.Parent.Touched:Connect(function(hit)
	if hit then
		if hit.Parent:FindFirstChild("Humanoid") then
			
			local ScreenGui = game.StarterGui.TeleportingGui:Clone()
			
			local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
			
			local Character = Player.Character
			local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
			
			ScreenGui.Parent = Player.PlayerGui
			ScreenGui.Enabled = true
			
			HumanoidRootPart.Position = Goal.Position
			HumanoidRootPart.Anchored = true
			
			ChangeSkyEvent:FireClient(Player)
			
			wait(1)
			HumanoidRootPart.Anchored = false
			ScreenGui:Destroy()
			
		end
	end
end)

Local script inside the starter player scripts:

local ChangeSkyEvent = game.ReplicatedStorage.ChangeSkyEvent

local OldSky = game.Lighting:WaitForChild("Sky")

local NewSky = game.ReplicatedStorage.NewSky

ChangeSkyEvent.OnClientEvent:Connect(function(Player)
	OldSky.Parent = game.ReplicatedStorage
	OldSky.Name = "OldSky"
	
	NewSky.Parent = game.Lighting
end)

This is the place if you want to take it:
TeleporterTest.rbxl (44.4 KB)

Explanation:

First of all, the sky needs to be in ReplicatedStorage or it will give an error.

Make two parts, one will be the teleporter and the other the goal or the end position.
inside the teleporter make a script.
and use this code:

local Goal = game.Workspace.Goal

local ChangeSkyEvent = game:GetService("ReplicatedStorage").ChangeSkyEvent

script.Parent.Touched:Connect(function(hit)
	if hit then
		if hit.Parent:FindFirstChild("Humanoid") then
			
			local ScreenGui = game.StarterGui.TeleportingGui:Clone()
			
			local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
			
			local Character = Player.Character
			local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
			
			ScreenGui.Parent = Player.PlayerGui
			ScreenGui.Enabled = true
			
			HumanoidRootPart.Position = Goal.Position
			HumanoidRootPart.Anchored = true
			
			ChangeSkyEvent:FireClient(Player)
			
			wait(1)
			HumanoidRootPart.Anchored = false
			ScreenGui:Destroy()
			
		end
	end
end)

change the variables for your own parts by the way.

Then make a RemoteEvent inside ReplicatedStorage, and also a local script inside starter player scripts

and use this code:


local ChangeSkyEvent = game.ReplicatedStorage.ChangeSkyEvent

local OldSky = game.Lighting:WaitForChild("Sky")

local NewSky = game.ReplicatedStorage.NewSky

ChangeSkyEvent.OnClientEvent:Connect(function(Player)
	OldSky.Parent = game.ReplicatedStorage
	OldSky.Name = "OldSky"
	
	NewSky.Parent = game.Lighting
end)

change the variables again for your own sky and RemoteEvent and there you have it.

if you don’t understand something in the code, tell me and i will explain it and give you the link to the Api reference.

if you want to change the sky again to the roblox default sky you only need to change the local script to this:

local ChangeSkyEvent = game.ReplicatedStorage.ChangeSkyEvent

local OldSky = game.Lighting:WaitForChild("Sky")

local NewSky = game.ReplicatedStorage.NewSky

ChangeSkyEvent.OnClientEvent:Connect(function(Player)
	OldSky.Parent = game.ReplicatedStorage
	OldSky.Name = "OldSky"
	
	NewSky.Parent = game.Lighting
	
	wait(2) -- amount of time that it takes to change the sky again to the default one
	
	NewSky.Parent = game.ReplicatedStorage
	OldSky.Parent = game.Lighting
end)

Also, there is a little problem with the UI of course. the ui can’t bypass the roblox top line where are the buttons. for that you can search in another topic, i will search for it because i don’t remember how it was.

if you need something more, tell me.

Hope it helps and good luck! :smile:

2 Likes

I just tried it and it works thank you so much.
Its everything I need I cant thank you enough thank you so much.

No problem :slight_smile: Tell me if you want more help in the future.

1 Like