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:
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)
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)