Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to Remove Model after Clone?

I am working on a game where you can buy items to decorate a base home, and I have 2 plots available ! is free and one is 250 coins.

I made it so you buy the 1st one, then once you buy the second one it removes plot one from the workspace, but I tried to make it so if you go back to edit the first one it rremoves the second one, but it won't run the script properly if you have never bought one yet.

Here is the script to purchase plot one.

local price = 0
Player = game.Players.LocalPlayer
ReplicatedStorage = game:GetService("ReplicatedStorage")
p1 = game.ReplicatedStorage.FreeMode.PlotOne
p2 = game.Workspace:WaitForChild:("PlotTwo")
usestat = "Coins"
blur = game.Lighting.Blur
buyplot = script.Parent.Parent
titlebar = script.Parent.Parent.Parent.TitleBar
local Cam = game.Workspace.CurrentCamera
be = script.Parent.Parent.Parent.BasicExit
mb = script.Parent.Parent.Parent.MainBottom

function onClicked()
	if game.Players.LocalPlayer.leaderstats[usestat].Value >= 0 then
		p2:Remove()
		p1:Clone()
		p1:Clone().Parent = game.Workspace
		wait(0.4)
		titlebar:TweenPosition(UDim2.new(0, 0, -1, 0), "Out", "Elastic", 1)
		wait(0.03)
		game.Players.LocalPlayer.leaderstats[usestat].Value = game.Players.LocalPlayer.leaderstats[usestat].Value - 0
		wait(2)
		buyplot:TweenPosition(UDim2.new(-1, -300, 0.5, -250), "Out", "Elastic", 1)
		wait(0.03)
		blur.Size = 9
		wait(0.4)
		blur.Size = 8
		wait(0.4)
		blur.Size = 7
		wait(0.4)
		blur.Size = 6
		wait(0.4)
		blur.Size = 5
		wait(0.4)
		blur.Size = 4
		wait(0.4)
		blur.Size = 3
		wait(0.4)
		blur.Size = 2
		wait(0.4)
		blur.Size = 1
		wait(0.4)
		blur.Size = 0
		wait(0.4)
		script.Parent.Parent.Parent.Parent.Parent.Character.Torso.CFrame = CFrame.new(-61, 23.7, 8)
		wait(0.03)
		if game.Players.LocalPlayer.leaderstats[usestat].Value > 1 then
			game.Players.LocalPlayer.leaderstats[usestat].Value = game.Players.LocalPlayer.leaderstats[usestat].Value + 0
		elseif game.Players.LocalPlayer.leaderstats[usestat].Value == 0 then
			game.Players.LocalPlayer.leaderstats[usestat].Value = game.Players.LocalPlayer.leaderstats[usestat].Value + 50000		
		end
		Cam.CameraSubject = Player.Character.Humanoid
		Cam.CameraType = "Custom"
		wait(0.03)
		be:TweenPosition(UDim2.new(1, -300, 1, -100), "In", "Elastic", 1)
		wait(0.5)
		mb:TweenPosition(UDim2.new(0, 0, 1, -50), "In", "Elastic", 1)
		wait(0.5)
	end
end

script.Parent.MouseButton1Click:connect(onClicked)

6 comments

0

What do you mean by "it won't run the script properly"? Be specific.

0

What is the problem? What does the output say? What happens with the plots? What does "It won't run the script properly" mean? This question does not describe,your problem

0

Is it failing? Is it lagging? How do you buy it? What is the currency? What do the local and dev logs say? What does the output say? is there any errors?

0

Is the model nor removing? Where is the script?

0

Basically, what I mean by it won't run properly is that when you choose to buy plot two, it removes plot one, assuming you will buy that one first, so if you edited plot two and want to go back to plot one, then it should remove plot two, but putting remove plot two in the script makes it break totally, so it can't run anything until it finds plot two.

0

That is the p2:remove() part, however it can't find p2 in the workspace when you buy plot one first so it doesn't run the script saying and infinite yield possible for "PlotTwo"

1 answer

Seems your script is broke by design.

You should put a check in. On purchase of each plot you should set a variable to true. To let the script know if the player owns it or not.

PlotOneOwned = false
PlotTwoOwned = false

if PlotOneOwned then
end

if PlotTwoOwned then
end

Your script isn't smart. It has no intelligence at all. Its up to the developer to counter these problems before the script is built You should've sat down and made a flow chart or thought out "Exactly" how your script will work before you started building it. Scripts can't assume what you want. You have to tell it what you want. Hopefully keeping this in mind will help you in the future.

1 comment

0

This is a smart idea, however I am getting errors. Like if you click return to menu after you have already bought plot one, and you return with plot two, it says plot one doesn't exist so it won't work.

This discussion is preserved as it was. New answers, comments, and votes are closed.