Car spawning that can only be seen by certain people

Hello, I’m making a car spawning system for a personal game.
I’m just wondering if someone can make a script where a text button can only be seen by certain people/players.

If you make the text button withing a local script, then it happens only on the client, so only certain people can see it. most car spawners use ProximityPrompt. I don’t know how you want yours to work, but those only appear to people close enough to them.

  1. Make textbutton in ScreenGui.
  2. Make local script inside textbutton
    LocalScript:
local button = script.Parent

local RepS = game:GetService("ReplicatedStorage")
local Touched = RepS:WaitForChild("CarSpawnTouched")
local SpawnCar = RepS:WaitForChild("SpawnCar")
Touched.OnClientEvent:Connect(function(bool)
  button.Visible = bool
end)
button.Visible = false
button.MouseButton1Click:Connect(function()
  SpawnCar:FireServer()
end)
  1. Make script in ServerScriptService
local Touchpart = workspace.SpawnCarPart
local canSpawn = {}

local RepS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Touched = RepS:FindFirstChild("CarSpawnTouched")
local SpawnCar = RepS:FindFirstChild("SpawnCar")
if not Touched then
  Touched = Instance.new("RemoteEvent", RepS)
  Touched.Name = "Touched"
end
if not SpawnCar then
  SpawnCar = Instance.new("RemoteEvent", RepS)
  SpawnCar.Name = "SpawnCar"
end

local isFired = {}
SpawnCarPart.Touched:Connect(function(hit)
  local char = hit.Parent
  if not char then return end
  if char==workspace then return end
  if isFired[char] then return end
  isFired[char] = true
  local player = Players:GetPlayerFromCharacter(char)
  if player then
    if canSpawn[player] then
      Touched:FireClient(player, true)
    end
  end
end)
SpawnCarPart.TouchEnded:Connect(function(hit)
  local char = hit.Parent
  if not char then return end
  if char==workspace then return end
  if not isFired[char] then return end
  isFired[char] = false
  local player = Players:GetPlayerFromCharacter(char)
  if player then
    if canSpawn[player] then
      Touched:FireClient(player, false)
    end
  end
end)
SpawnCar.OnServerEvent:Connect(function(player)
  if canSpawn[player] then
    -- spawn car
  end
end)
1 Like

Thank you so much! This helped.