Converting player join localscript into serverscript

im trying to make a model appear when someone joins and disappear when that person leaves. ive got a script working where it makes the model visible when someone joins but im dumb and just now realized that it only shows for one person because i made it a localscript. im fairly new to scripting so i have no idea how to make this into a server script; any help is appreciated.

my current localscript that is in StarterPlayerScripts:
playerjoin script

1 Like

Paste the same thing into a server script, aka “Script” in case you didn’t know, preferrably placed inside ServerScriptService. Everything would function normally with no need for any changes.

Create a serverscript in ServerScriptService and :

local Players = game:GetService("Players")
local Model = workspace:WaitForChild("suitcase1")

local function onPlayerAdded(player)
for _,part in pairs(Model:GetDescendants()) do
  if part:IsA("MeshPart") then
     part.Transparency = 0
     part.CanCollide = true
    end
end
end
local function onPlayerRemoving(player)
for _,part in pairs(Model:GetDescendants()) do
  if part:IsA("MeshPart") then
     part.Transparency = 1
     part.CanCollide = false
    end
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
Players.PlayerRemoving:Connect(onPlayerRemoving)
1 Like

i get these errors in game
image

can you show me what’s in your suitcase1 instance?

image
these all have surfaceappearance’s in them

1 Like

mb, i fixed the code you can try again.
should work now.

1 Like

studio now shows this and says error on line 20
image

1 Like

i fixed it up there, Type onPlayerAdded instead of OnPlayerAdded
and onPlayerRemoving instead of OnPlayerRemoving
meaning just make the O lowercase.

game is now showing this again
image

1 Like
local Players = game:GetService("Players")
local Model = workspace:WaitForChild("suitcase1")

local function onPlayerAdded(player)
for _,part in pairs(Model:GetDescendants()) do
  if part:IsA("MeshPart") then
     part.Transparency = 0
     part.CanCollide = true
    end
end
end
local function onPlayerRemoving(player)
for _,part in pairs(Model:GetDescendants()) do
  if part:IsA("MeshPart") then
     part.Transparency = 1
     part.CanCollide = false
    end
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
Players.PlayerRemoving:Connect(onPlayerRemoving)
1 Like

that fixed it thank you!!!

1 Like