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

How to get only one player in a GUI and not all?

Asked by 1 year ago

So I'm having a problem where I want ONLY the person who touched a pad to see a GUI, the problem is that I think the i,v in pairs is taking all players, even despite me using the PlayerGui. How can I get around this? LocalScript:

local debounce = false
local function popup()
    if not debounce then
        debounce = true
        game.Workspace.BackroomsSound:Stop()
        for i,v in pairs (game.Players:GetPlayers()) do
            local Frame = v.PlayerGui.LevelChanges.PipeDreams       
            local Text = Frame.text
            Frame.Visible = true
            wait(5)
        while true do
            script.Parent.BackgroundTransparency = script.Parent.BackgroundTransparency + 0.05
            wait(0.05)
            if  script.Parent.BackgroundTransparency >= 1 then 
                break
            end
        end
            script.Parent.text.TextTransparency = 1
            game.Workspace.BackroomsSound:Play()
            wait(1)
            debounce = false
        end
    end
end

game.Workspace.pad1.Touched:Connect(popup)

1 answer

Log in to vote
0
Answered by 1 year ago

You can check if the player touching the pad is LocalPlayer (keep in mind that LocalPlayer only exists in local scripts, so don’t attempt this on server scripts).

You should also replace the loop with TweenService, as it is smoother and does not create unnecessary burdens.

Lastly, try not using wait(), but if you must, use task.wait(), it is an “improved” version of wait().

So something like this:

local Players = game:GetService('Players')
local TweenService = game:GetService('TweenService')

local debounce = false
local localPlayer = game.Players.LocalPlayer

workspace.pad1.Touched:Connect(function(hit)
    if localPlayer.Name == hit.Parent.Name and not debounce then
        debounce = true

        local Frame = localPlayer.PlayerGui.LevelChanges.PipeDreams
        workspace.BackroomsSound:Stop()
        Frame.Visible = true
        task.wait(5)
        TweenService:Create(script.Parent, TweenInfo.new(), {BackgroundTransparency = 1}):Play()
        script.Parent.text.TextTransparency = 1
        workspace.BackroomsSound:Play()

        task.wait(1)
        debounce = false
    end
end)
Ad

Answer this question