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

instance that adds parts after deletion ?

i am trying to make a script that adds a part after deleting a part by pressing the "delete" key ,this is in a local script


local UserInputService = game:GetService("UserInputService")


local part = game.Workspace.Part
UserInputService.InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.Delete then
		part:Destroy()
		
		
	end
	
end)

thank you

1 comment

0

Do you want it to show up to everyone or just the player?

1 answer

✓ Accepted answer
--[[
make an event that fires when it destroys
]]

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:connect(function(input)
    if input.KeyCode == Enum.KeyCode.Delete then
	local part = game.Workspace:FindFirstChild'Part' or nil
	if part then
        	part:Destroy()
		game.ReplicatedStorage.Events.RemakePart:FireServer() 
	end
    end
end)

--[[
put this in a server script somewhere
]]

game.ReplicatedStorage.Events.RemakePart.OnServerEvent:Connect(function()
	Instance.new('Part', game.Workspace).Position = Vector3.new(0,0,0) -- make part and put position u want
end)

2 comments

0

event:FireServer() after you destroy it --[[line 12 in my script]] https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

0

Only the player that deleted the part will see the part delete!

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