Prevent Inventory Use If A Model Is In Workspace

I’m trying to make a script that prevents the player from using their inventory for a few seconds after a model named “Map” has been placed in the workspace.

Here is the script I have in ServerScriptService:

if Map:IsDescendantOf(game.Workspace) then
	game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false)
	wait(10)
		game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,true)
	end

The model “Map” appears in the workspace when testing but the script does not run and prevent the player from using their inventory.

1 Like

maybe try

thing:GetPropertyChangedSignal('Parent'):Connect(function()
    local newParent = thing.Parent
    -- do things
end)

Doesn’t seem to work. I might have done something wrong though is this correct:

Map:GetPropertyChangedSignal('Parent'):Connect(function()
local newParent = Map.Parent
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false)
wait(10)
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,true)
end)

on first look it seems good but after more reSearch it is not
try

game:GetService('RunService').Heartbeat:Connect(function()
    local newParent = thing.Parent
    -- do things
end)

You must use a LocalScript to StarterGui:SetCoreGuiEnabled()

Map.AncestryChanged:Connect(function()
	if Map:IsDescendantOf(workspace) then
		game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false)
		task.wait(10)
		game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,true)
	end
end)

So I put the code in a LocalScript in ServerScriptService and it did not work. I tried it in the workspace and StarterPlayerScripts but neither worked either.

I am assuming you already have a variable set to the model named Map somewhere, basically put this in the script and put this script inside StarterPlayerScripts

It MUST be a LocalScript

local Map = **where the model is located currently, ReplicatedStorage is recommended** 
-- local Map = game.ReplicatedStorage:WaitForChild("Map")

Map:GetPropertyChangedSignal('Parent'):Connect(function()
    if Map:IsDescendantOf(workspace) then
		game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false)
		task.wait(10)
		game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,true)
	end
end)

This way everytime you parent the model Map else where it will fire this event and if the model is parented to workspace it should disable the toolbar/backpack for ten seconds

So the way I’m doing it is I have multiple maps in a folder in ReplicatedStorage and the game clones one to the workspace and names it map. It doesn’t move it.

then in that case you should do

workspace.ChildAdded:Connect(function(object)
	if object.Name == "Map" then
		game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false)
		task.wait(10)
		game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,true)
	end
end)

This also belongs in a local script inside StarterPlayerScripts, just make sure you name the map model Map before it gets parented to workspace and not after it gets parented

1 Like