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

How can I destroy a local part?

I am currently making a game on roblox where players earn points and then level up after so many points are gained.

I want to make a door that is destroyed when a player reaches level 2 but I only want the door to destroy for the local player.

I created a door and then put the door into ReplicatedStorage. I then created a localscript in startergui (I did this as I want the script to run on the client-side, not the server)

This is my localscript that is in startergui

local player = game.Players.LocalPlayer
local level = player.leaderstats:WaitForChild("Level")
local part = game.ReplicatedStorage.Doors.Level2Door


local clone = part:Clone()
	clone.Parent = game.Workspace

level.Changed:Connect(function(Val)
	if level >= 2 then
		clone:Destroy()
	end
end)

The door does clone and is in the Workspace but when I tested it, I get to level 2 but the door does not get destroyed and remains in place.

Can someone give me some idea of how to fix it so the door will get destroyed for the local player when they get to level 2?

Thanks everyone!

1 answer

✓ Accepted answer

The reason why it won't destroy when your level reaches 2 is because you're not actually checking if the level's value is above or equal to 2. You'll need to add .Value on the end of 'level' on line 10 to get the level's value property, then you can check if the value of it is above or equal to 2.

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