Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make Gui for the player who Touched it Only?

Asked by 5 years ago

Help me pls, I put LocalScript In Gui And It didnt work, no errors, nothing happens It still shows for all players: https://gyazo.com/b674b7ec1881b1916c3c811c6785c034 this is my code in LocalScript in StarterGui

01local playerGui = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui")
02cloneGui = script.Parent.Info
03 
04game.Workspace.Stages["2"].Touched:Connect(function(hit)
05    local Hu = hit.Parent:FindFirstChild("Humanoid")
06    if Hu then
07        cloneGui.Frame.TextLabel.Visible = true
08        cloneGui.Parent = playerGui
09    end
10end)
0
I know, this code is stupid, i just noticed AnasBahauddin1978 715 — 5y

1 answer

Log in to vote
3
Answered by
pwx 1581 Moderation Voter
5 years ago

An easier way to do this is detect via Server-Side then use a RemoteEvent to fire the client.

Like so:

Server Script

01-- Put this script inside the part you want touched to activate the UI.
02local part = script.Parent
03local Players = game:GetService('Players')
04local RS = game:GetService('ReplicatedStorage')
05 
06 
07part.Touched:Connect(function(otherPart)
08    local Player = Players:GetPlayerFromCharacter(otherPart.Parent)
09    if Player then
10        RS.RemoteEvent:FireClient(Player, 'Stage Two: Water!') -- first parameter being the client we are firing, second being the text
11    end
12end)

Now, for the local script. Preferably put this inside StarterGui or the UI itself, doesn't matter.

LocalScript

01local Player = game.Players.LocalPlayer
02local RS = game:GetService('ReplicatedStorage')
03 
04function textActivated(textInfo)
05    local textlabel = **TextLocationHere**
06    if textlabel.Visible == false then
07        textlabel.Visible = true
08        textlabel.Text = textInfo -- this will be the text you sent over
09        wait(2)
10        textlabel.Visible = false
11    end
12end
13 
14RS.RemoteEvent.OnClientEvent:Connect(textActivated)

In hindsight, you'll be able to use the same remote for each level change, just by changing the remote parameter to what you desire. The code is somewhat messy and rushed and could probably be a lot shorter but it's early in the morning and I haven't had my tea yet.

Either way, give that a go and let you know if you need any help.

0
Thanks A Lot for this! AnasBahauddin1978 715 — 5y
0
this worked AnasBahauddin1978 715 — 5y
0
No worries. pwx 1581 — 5y
Ad

Answer this question