Everyone sees the ScreenGUI

Hello community, I need to ask you a help, and it’s about a door that is blocked and when you touch it you show the ScreenGui to the player, but when you make the purchase, the other players can also pass the door…
In order to open this portal, there is a LocalScript and it calls the RemoteEvent “PortalUno”,

LocalScript:

local RemoteEvent = game.ReplicatedStorage.PortalUno 

script.Parent.MouseButton1Click:Connect(function()

RemoteEvent:FireServer()

end) 

And this Remote event calls a Normal Script.

Script:

local RemoteEvent = game.ReplicatedStorage.PortalUno

RemoteEvent.OnServerEvent:Connect(function(player)
	if player.leaderstats['🌟 Food'].Value > 0 then
		player.leaderstats['🌟 Food'].Value -= 5000
		wait()
		game.Workspace.Portales.PortalUno:Destroy()
		game.StarterGui.BuyZoneUnderwater.Hijo.Visible = false
	elseif player.leaderstats['🌟 Food'].Value < 0 then
		game.StarterGui.BuyZoneUnderwater.Hijo.Visible = false
	end
end)

I need this portal to be unlocked only to the person who bought it, not to the whole server. Please help

Destroy it on the client with the remote firing back. Clients have their own environments.

1 Like

It does not work. What can I do?

It should work if you fire the remote back at the player. Write a function connecting to that remote which destroys that.

game.StarterGui.BuyZoneUnderwater.Hijo.Visible = false

Consider controlling graphical user interface elements in the client context, not server

As you are destroying the PortalUno Object in the server context, everyone in the server can see the changes, if you want only a specific player to see the changes, consider doing it in the client context instead. As this isn’t a lot of code, I’ll edit your client’s code.

– Client context

--// Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--// Paths
local user = Players.LocalPlayer
local portalUno = workspace:WaitForChild("Portales"):WaitForChild("PortalUno")
local remoteEvent = ReplicatedStorage:WaitForChild("PortalUno")

--// Events
script.Parent.MouseButton1Click:Connect(function()
    if user.leaderstats["🌟 Food"].Value > 0 then
        user.PlayerGui.BuyZoneUnderwater.Hijo.Visible = false
        portalUno:Destroy()
        remoteEvent:FireServer()
    else
        user.PlayerGui.BuyZoneUnderwater.Hijo.Visible = false
    end
end)

– Server context

--// Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--// Paths
local remoteEvent = ReplicatedStorage:WaitForChild("PortalUno")

--// Events
remoteEvent.OnServerEvent:Connect(function(user)
    if user.leaderstats["🌟 Food"].Value > 0 then
        user.leaderstats["🌟 Food"].Value -= 5000
    end
end)

Good luck!

1 Like