Here is the client side:

local runService = game:GetService("RunService")

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local DeleteRE = game.ReplicatedStorage.remotes.Delete
local button = script.Parent.Parent

local obj

local Isdelete = false

script.Parent.MouseButton1Click:Connect(function()
	if Isdelete then
		Isdelete = false
		button.ImageColor3 = Color3.new(255,0,0)
	else
		Isdelete = true
		button.ImageColor3 = Color3.new(0,255,0)
	end
end)

mouse.Button1Down:Connect(function()
	if obj and mouse.Target == obj then
		DeleteRE:FireServer(obj.Parent)
	end
end)

runService.RenderStepped:Connect(function()
	if Isdelete then
		if mouse.Target then
			if mouse.Target.Name == "Primary" then
				obj = mouse.Target
			end
		end
	else
		obj = nil
	end
end)

And here is Sever side:

local DeleteRE = game.ReplicatedStorage.remotes.Delete

DeleteRE.OnServerEvent:Connect(function(plr, obj)
	obj:Destroy()
end)

Not deleting though. The object does have a primary part names "Primary", which is anchored, and no errors are coming through. Why is this happening?

Edit: The script works if i try to delete things that are loaded from the save script. But as soon as i place a new object down, it prevents me from deleting anything.

2 comments

0

Errors?

0

no