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!
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)
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
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)
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)
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
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)
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.