Local gui - Not for all

I have script

game.ReplicatedStorage.NeedMoney.OnServerEvent:Connect(function()
	script.Parent.Visible = true
end)

But i need to gui show not for all player.

game.ReplicatedStorage.Carhandler.OnClientEvent:Connect(function(car)
	local text = script.Parent.Frame.TextLabel
	if car == "Car1" then
		text.Text = "Would you like to buy the Purple Sports W1 for $5000?"
		script.Parent:TweenPosition(UDim2.new(0.336,0,0.2,0), "Out", "Bounce", 1)
	elseif car == "Car2" then
		text.Text = "Would you like to buy the Yellow Sports W2 for $10000?"
		script.Parent:TweenPosition(UDim2.new(0.336,0,0.2,0), "Out", "Bounce", 1)
	elseif car == "Car3" then
		text.Text = "Would you like to buy the Blue Sports Pro W1 for $20000?"
		script.Parent:TweenPosition(UDim2.new(0.336,0,0.2,0), "Out", "Bounce", 1)
	elseif car == "Car4" then
		text.Text = "Would you like to buy the Orange Sports Pro W2 for $20000?"
		script.Parent:TweenPosition(UDim2.new(0.336,0,0.2,0), "Out", "Bounce", 1)

			
	end
	script.Parent.Frame.No.MouseButton1Click:Connect(function()
		script.Parent:TweenPosition(UDim2.new(0.336,0,-1,0), "Out", "Quad", 1)
	end)
	script.Parent.Frame.Yes.MouseButton1Click:Connect(function()
		script.Parent:TweenPosition(UDim2.new(0.336,0,-1,0), "Out", "Quad", 1)
		local plr = game.Players.LocalPlayer
		if car == "Car1" then
			if plr.leaderstats.Money.Value < 5000 then
				game:GetService("ReplicatedStorage").NeedMoney:FireServer(plr)
			else
				game.ReplicatedStorage.Carhandler:FireServer(car)
			end
		end
		if car == "Car2" then

			if plr.leaderstats.Money.Value < 10000 then
				game:GetService("ReplicatedStorage").NeedMoney:FireServer(plr)
			else
				game.ReplicatedStorage.Carhandler:FireServer(car)

			end
		end
		if car == "Car3" then
			if plr.leaderstats.Money.Value < 20000 then
				game:GetService("ReplicatedStorage").NeedMoney:FireServer(plr)
			else
				game.ReplicatedStorage.Carhandler:FireServer(car)

			end
		end
		if car == "Car4" then
			if plr.leaderstats.Money.Value < 20000 then
				game:GetService("ReplicatedStorage").NeedMoney:FireServer(plr)
			else
				game.ReplicatedStorage.Carhandler:FireServer(car)
			end
		end
	end)
end)

This is game:GetService(“ReplicatedStorage”).NeedMoney:FireServer(plr)

gme.ReplicatedStorage.NeedMoney.OnServerEvent:Connect(function(sender,plrName)
	if plrName == *PlayerName then
-- script
end
end)

image

image

can u show explorer where script is?

You can just use this in your local script. Instead of game.ReplicatedStorage.Carhandler:FireServer(car)

use

script.Parent.Visible = false

You don’t need to handle the GUIs visibility from the server.

image

No. I can’t use local script b

gme.ReplicatedStorage.NeedMoney.OnServerEvent:Connect(function(sender,plrName)
	if plrName == script.Parent.Parent.Parent.Parent.Name then
-- script
end
end)

But you can’t use OnClientEvent unless it is a local script. Would you mind changing the script type to LocalScript?

No i can’t. It will create bugs

It isn’t works. Idk why. May be i need to use Players.PlayerGui.ScreenGui.Enabled = true but idk how

Are you sure some bugs will appear after you change it to LocalScript? If you think like that, for what reasons you don’t change it? OnClientEvent will only work for local scripts.

OK. which script do I need to use in LocalScript?

What is it you’re trying to achieve? Is this post about making a buy car confirmation GUI appear only for one player? From what it looks like, you have code for controlling the GUI in a server script. If this is true, then you should not be doing this. ScreenGui objects are not controlled server-side because servers do not need GUI–only players. Therefore, code you have that modifies and responds to GUI should be in LocalScripts. Code that deals with data, such as subtracting a player’s points to purchase an item, should be dealt with server-side (for security reasons).

I cannot use the local script because then I cannot close this interface from the server side.

Is the interface you are referring to the GUI?

image
Panel

As I stated earlier, GUI should not be accessed in server scripts. IIRC, the roblox API explicitly states that ScreenGui elements (and elements put as children under a ScreenGui) are non-modifiable (and maybe even non-visible) to the server. Another thing to note is that your server script may not even be running. Server scripts do not run under PlayerGui. Your Panel ImageLabel is a child of the ScreenGui TeamChange which is a child of StarterGui. This means that when you hit “Play” (or “Play Here”) in Studio, TeamChange (and inherently Panel) is put under PlayerGui. ​This also means that your Script that is under Panel is under PlayerGui, which means that it will not run.

You will need to move your code around such that code dealing with the GUI is in a LocalScript and code dealing with data remains in the server script. If you’re having trouble with figuring out how to do this, then think of it this way:

  1. In a LocalScript, have code that deals with the animation (or Tweening) of GUI elements and responds to inputs (i.e. clicking a GUI button)
  2. When a button that deals with important player data (such as a button that purchases something or gives a player an item) is clicked, fire an event to the server
  3. In a ServerScript, listen for such events. When an event is received, handle it accordingly. For example, a PurchaseCarR32 event. When PurchaseCarR32 event is fired, this means that the player wants to purchase an R32. In the ServerScript, check that the player has the correct amount of points to purchase the R32. If they have the right amount, purchase it and subtract points. You can fire another event back to the client to signify if the purchase was successful.
    a) A note about the example event I gave: in my specific example, it would be better to have an event named PurchaseCar and then pass it the string “R32” to specify which car to purchase. This way, you wouldn’t have to create a PurchaseCarName event for every single car and could instead only use the one PurchaseCar event and pass it a parameter.

To deal with the server script (which currently does not run since it is under PlayerGui), consider moving it into ServerScriptService. ServerScripts under SSS will run. It is okay to put it under SSS because all the script consists of are event listeners. The ServerScript will not need access to the GUI elements because it will not (and should not) interact with those elements.