im tryna make a script where if u step on a part it creates a screengui and then creates a text label.
1 | text = Instance.new( "TextLabel" ) |
2 | screen = Instance.new( "ScreenGui" ) |
3 | script.Parent.Touched:Connect( function (hit) |
4 | if hit.Parent:IsA( "Player" ) then |
5 | screen.Parent = game.StarterGui |
6 | text.Parent = game.StarterGui:WaitForChild( "ScreenGui" ) |
7 | text.Text = "Welcome" |
8 | end |
9 | end ) |
your entire script is wrong if your game is not in experimental mode, then you need to use a RemoteEvent, that should be parented to game.ReplicatedStorage, but I assume you don't know how to do that so I comment every line in the following script with detailed explanations
Server Script (For creating the remote, and handling the Touched event) The Server Script should be inside the Part.
01 | local NewGui = Instance.new( "RemoteEvent" ) --Create the remote |
02 | NewGui.Name = "NewGui" --Name the remote |
03 | NewGui.Parent = game.ReplicatedStorage --Put the remote in ReplicatedStorage |
04 |
05 | script.Parent.Touched:Connect( function (Hit) --When script.Parent is touched, define 'Hit' as what touched it |
06 | local Player = game.Players:GetPlayerFromCharacter(Hit.Parent) --Attempt to get the player who touched it, by using the GetPlayerFromCharacter method that gets a player by his character |
07 | if Player ~ = nil then --If it was really a player that touched it, then |
08 | NewGui:FireClient(Player) --Fire the remote on the client |
09 | end |
10 | end ) |
Local Script (For handling the Remote, and creating the Gui) The Local Script should be inside StarterGui.
1 | game.ReplicatedStorage:WaitForChild( "NewGui" ).OnClientEvent:connect( function () --When NewGui is triggered by the server script on the player |
2 | local ScreenGui = Instance.new( "ScreenGui" ) --Create the ScreenGui |
3 | local TextLabel = Instance.new( "TextLabel" ) --Create the TextLabel |
4 | ScreenGui.Parent = script.Parent --Put the ScreenGui in PlayerGui |
5 | TextLabel.Parent = ScreenGui --Put the TextLabel in ScreenGui |
6 | TextLabel.Text = "Welcome" --Change the TextLabel's Text |
7 | end ) |
if filtering enabled make a bindable event called openui in replicated storage this script goes in the part
1 | script.Parent.Touched:Connect( function (hit) |
2 | if hit.Parent:IsA( "Player" ) then |
3 | game.ReplicatedStorage.OpenGui:Fire(Hit.Parent.Name) |
4 | end |
5 | end ) |
this goes in a script in server script service
1 | game.ReplicatedStorage.OpenGui.Event:Connect( function (plrName) |
2 | text = Instance.new( "TextLabel" ) |
3 | screen = Instance.new( "ScreenGui" ) |
4 | local plr = game.Players [ plrName ] |
5 | screen.Parent = plr.PlayerGui |
6 | text.Parent = Plr.PlayerGui:WaitForChild( "ScreenGui" ) |
7 | text.Text = "Welcome" |
8 | end ) |