[SOLVED] How to make a script where when you say a certain thing it spawns in a model at your character?

Okay and the issue with that?

Only you have access to the command, so it cant be abused.

But soon im realising the game to a certain group role.

Alright, so what do you want it to be like, explain the rules to me.

i would like it to kinda be like the maximum amount of planes in 3 and also a delete plane command (if that’s possible) tysm!

Alright, what do you think is the best way to do this?

I would say tables and using the destroy function.

It’s best usually if you can build trust with your staff though.

I could make an acceptation form not to abuse it.

However, if it’s required, I’m sure we could figure out a way.

That’s up to you.

I guess your correct

all i want is just a delete command

Alrighty, we can add that.

So have you heard of the Instance:Destroy() function?

I’ve heard of Destroy() but not instance

Ah instance is just a fancy way of saying an object (basically).

oh okay now it makes sense.

So basically if i do:

local part = script.Parent
part:Destroy()

it will destroy the part?

Yeh, that’s how it will work.

I’m writing the script and adding comments to explain it right now…

thank you so much! :smiley:

Alright, here is the script, make this post the solution if it fixes it.

The one issue, is the command will delete other peoples planes, so I’ve added a little fix, it’s not the best way to go around the issue, but it does the trick.

local groupId = 12760887 --Define the GroupId variable
local rank = 0 --Define the MinRank Variable
local Model = game.ReplicatedStorage:WaitForChild("Model")  --Wait to see if "Model" is inside of Replicated Storage, just incase a loading issue or something else affects it.


game.Players.PlayerAdded:Connect(function(player) --When the player joins get the Player Instance.
	player.Chatted:Connect(function(msg) --Detect whenthe player chats and get the message they sent. 
		if msg == ":spawn plane" and player:GetRankInGroup(groupId) == rank then --Check the msg they sent, see if the message is ":spawn plane" and check if the person has the correct rank, if they do continue.
			local clone = Model:Clone() --Clone the model we defined earlier on.
			clone.Name = "Plane" ..player.Name --Makes the plane have a unique name.
			clone.Parent = game.Workspace --Set the models parent, so we can see it in workspace.
			clone:MoveTo(player.Character.HumanoidRootPart.Position) --Set the model to be were the player is.
		else if msg == ":destroy plane" then
				for i, v in pairs(game.Workspace:GetChildren()) do --Forloop, loops through the workspace directory
					if v.Name == "Plane" ..player.Name then --Checks if the name of the plane matches the name of the person who ran the command
						v:Destroy() --Destroy the plane, bye bye plane.
					end
				end
			end
		end
	end)
end)