How to make parts spawn only on public server?

I got a problem, where i need to make parts not being able to spawn at vip servers, but only on public servers, i tried many things but nothing works.

this is script i made, but it just dont work

if not (game.VIPServerId ~= "" and game.VIPServerOwnerId == 0) then
	local presents = script.Presents:Clone()
	presents.Parent = workspace
end

please help me im very confused

2 Likes

You can modify your script to check if the game is running on a public server using game.PrivateServerId. Here’s the corrected version of your script:

if game.PrivateServerId == "" then
    local presents = script.Presents:Clone()
    presents.Parent = workspace
end

game.PrivateServerId is an empty string (“”`) when the game is running on a public server. On VIP servers, it will contain a unique ID.change the name of the code to fit the names of your code

The condition if game.PrivateServerId == "" ensures the parts only spawn on public servers.

This should solve the problem. Let me know if it works

5 Likes

just so you know this code is only to differenciate the servers not to stop sm from apearing

3 Likes

so that mean it still can spawn in vip servers?

yes it only makes the diffrence it dosent tell the game not to spawn it

4 Likes

so you need to add the object you want not to spawn it adds a new id to the vip server

4 Likes

local objectName = “Deez Nuts”
local workspace = game:GetService(“Workspace”)

local function handlePrivateServer()
if game.PrivateServerId ~= “” then
local object = workspace:FindFirstChild(objectName)
if object then

        object:Destroy()
    end
end

end

handlePrivateServer()

workspace.ChildAdded:Connect(function(child)
if game.PrivateServerId ~= “” and child.Name == objectName then

    child:Destroy()
end

end)
so this script should be put in serverscript service and the script checks the server for the kind stops the object in workspace from spawning and if it spawns it emidiantly delets it just remember the deez nuts name should be changed to whatever object you dont want to spawn

5 Likes

also i have a question, sorry if annoying you, but you know why this script doesnt working, it should shutdown server after 8 hours in public server but doesnt do anything.

task.wait(1)
if game.PrivateServerId ~= "" then
repeat task.wait(0) until game.Workspace.DistributedGameTime >= 28800
	for i,Player in pairs(game.Players:GetPlayers()) do
		Player:Kick('The server was shutdowned, Reason: Servers Closing after 8 Hours')
	end
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.