I cant sit after i closing gui

When i sit on seat and close gui i cant able to sit on seat

Server Script:

task.wait(3)
local seat = script.Parent
local companys = game:GetService('Workspace'):WaitForChild('Companys')
local function onOccupantChanged()
	local humanoid = seat.Occupant
	if humanoid then
		local character = humanoid.Parent
		local player = game.Players:GetPlayerFromCharacter(character)
		if player then
			local PlayerScripts = player:WaitForChild("PlayerScripts")
			local PlayerModule = require(PlayerScripts:WaitForChild("PlayerModule"))
			local PlayerControls = PlayerModule:GetControls()

		if script.Parent.Parent.Parent.Parent:GetAttribute('Id') == player.UserId then
 				PlayerControls:Disable()
				local gui = player.PlayerGui.Pc.PcUI
				gui.Visible = true
			else
				seat:FindFirstChild('SeatWeld'):Destroy()
			end
		end
	end
end
seat:GetPropertyChangedSignal("Occupant"):Connect(onOccupantChanged)

Client Script (local)

task.wait(3)
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local PlayerScripts = Player:WaitForChild("PlayerScripts")
local PlayerModule = require(PlayerScripts:WaitForChild("PlayerModule"))
local PlayerControls = PlayerModule:GetControls()
local playergui = Player.PlayerGui
local character = Player.Character
local humanoid = character:WaitForChild('Humanoid')
local Module = require(game:GetService('ReplicatedStorage'):WaitForChild('Module'))
local companys = game:GetService('Workspace'):WaitForChild('Companys')
script.Parent.MouseButton1Click:Connect(function()
	local ownedCompany = nil
	
	ownedCompany = Module.findCompany(Player)
	 
	ownedCompany:WaitForChild('PC1'):WaitForChild('Chair'):WaitForChild('Seat'):FindFirstChild("SeatWeld"):Destroy()
	local gui = playergui.Pc.PcUI
	gui.Visible = false
	PlayerControls:Enable()

end) 

It doesnt giving any errors

Don’t delete the SeatWeld from the client.
Delete it from the server.

1 Like

so i need add remote events?
:face_with_spiral_eyes:

Yup. You gotta add the RemoteEvents.

How can it be manipulated?

eeeeeeeee

So does my suggestion work as intended?

You gotta like send fire the event from the LocalScript after you clicked the button.

And the script responds by deleting the SeatWeld.

task.wait(3)
local seat = script.Parent
local pl
local companys = game:GetService('Workspace'):WaitForChild('Companys')
local function onOccupantChanged()
	local humanoid = seat.Occupant
	if humanoid then
		local character = humanoid.Parent
		local player = game.Players:GetPlayerFromCharacter(character)
		if player then
			local PlayerScripts = player:WaitForChild("PlayerScripts")
			local PlayerModule = require(PlayerScripts:WaitForChild("PlayerModule"))
			local PlayerControls = PlayerModule:GetControls()

			if script.Parent.Parent.Parent.Parent:GetAttribute('Id') == player.UserId then
				pl = player
 				PlayerControls:Disable()
				local gui = player.PlayerGui.Pc.PcUI
				gui.Visible = true
				
			else
				seat:FindFirstChild('SeatWeld'):Destroy()
			end
		end
	end
end
seat:GetPropertyChangedSignal("Occupant"):Connect(onOccupantChanged)
local remote = game:GetService('ReplicatedStorage'):WaitForChild('SW')
remote.OnServerEvent:Connect(function(plr,something)
	if plr.UserId == pl.UserId then
		seat:FindFirstChild('SeatWeld'):Destroy()
		local PlayerScripts2 = plr:WaitForChild("PlayerScripts")
		local PlayerModule2 = require(PlayerScripts2:WaitForChild("PlayerModule"))
		local PlayerControls2 = PlayerModule2:GetControls()

		local gui1 = plr.PlayerGui.Pc.PcUI
		gui1.Visible = false
		PlayerControls2:Enable()
	end
end)




close script

script.Parent.MouseButton1Click:Connect(function()
	remote:FireServer("something")
end) 

What does this line compare? What does it do?

it does if player is ownes this base

So does the GUI appear when you sit on the part?

yes everything works but when i sit again i cant sit

Off-topic question but, how did you get PlayerScripts from a server script?

i got from player.PlayerScripts

1 Like

Weird. I got an error for that.