Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why this script is appearing for everyone, but it's local?

I'm very new to this forum and to lua scripting, i need help, this code is in a local script but it appears for everyone...

This code is for when the player sits, appear a GUI for local player, but it's appearing for all players, can someone explain me, I'm NOT requesting a new script

Code:

local seat = workspace.OfficeChair1.Seat
local ui = script.Parent

while true do
    wait(1)
    if seat.Occupant == nil then
        ui.Visible = false
    else
        ui.Visible = true
    end
end


1 comment

0

your checking if it has an occupant not if the occupant is the player that has the local script.

2 answers

make the code check to make sure the occupants name is the same as the game.Players.LocalPlayer 's name. that should fix it.

I'll just supplement 129Steve129's response with the following code:

local seat = workspace.OfficeChair1.Seat
local ui = script.Parent
local player = game.Players.LocalPlayer

while true do
	wait(1)
	if seat.Occupant == nil or seat.Occupant.Parent.Name ~= player.Name then
		ui.Visible = false
	else
		ui.Visible = true
	end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.