Ad
Log in to vote
0

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

Asked by 3 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

local playerGui = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui")
cloneGui = script.Parent.Info

game.Workspace.Stages["2"].Touched:Connect(function(hit)
    local Hu = hit.Parent:FindFirstChild("Humanoid")
    if Hu then
        cloneGui.Frame.TextLabel.Visible = true
        cloneGui.Parent = playerGui
    end
end)
0
I know, this code is stupid, i just noticed AnasBahauddin1978 715 — 3y

1 answer

Log in to vote
3
Answered by
pwx 1546 Moderation Voter
3 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

-- Put this script inside the part you want touched to activate the UI.
local part = script.Parent
local Players = game:GetService('Players')
local RS = game:GetService('ReplicatedStorage')


part.Touched:Connect(function(otherPart)
    local Player = Players:GetPlayerFromCharacter(otherPart.Parent)
    if Player then
        RS.RemoteEvent:FireClient(Player, 'Stage Two: Water!') -- first parameter being the client we are firing, second being the text
    end
end)

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

LocalScript

local Player = game.Players.LocalPlayer
local RS = game:GetService('ReplicatedStorage')

function textActivated(textInfo)
    local textlabel = **TextLocationHere**
    if textlabel.Visible == false then
        textlabel.Visible = true
        textlabel.Text = textInfo -- this will be the text you sent over
        wait(2)
        textlabel.Visible = false
    end
end

RS.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 — 3y
0
this worked AnasBahauddin1978 715 — 3y
0
No worries. pwx 1546 — 3y
Ad

Answer this question