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
What do you mean by "it won't run the script properly"? Be specific.
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
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?
Is the model nor removing? Where is the script?
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.
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"