Placing not working

I am trying to create a part that transfers all the properties of the old part into the server and deleting the old one for a placement system.
When I press the button, it simply just creates a ton of parts that do absolutely nothing.

Localscript (in a button in startergui)

local button = script.Parent
local PlaceEvent = game.ReplicatedStorage:WaitForChild("Events").PlaceEvent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local RS = game:GetService("RunService")
local UIS = game:GetService("UserInputService")

button.MouseButton1Down:Connect(function()
	local part = game.ReplicatedStorage.Towers.Part:Clone()
	part.Parent = workspace
	placeRSF = RS.RenderStepped:Connect(function()
		part.Position = mouse.Hit.p
		UIS.InputBegan:Connect(function(input)
			if input.UserInputType == Enum.UserInputType.MouseButton1 then
				PlaceEvent:FireServer(part.CFrame.p)
				part:Destroy()
				placeRSF:Disconnect()
			end
		end)
	end)
end)

ServerScript (in serverscriptservice)

local RS = game:GetService("ReplicatedStorage")
local events = RS:WaitForChild("Events")
local placeEvent = events.PlaceEvent

placeEvent.OnServerEvent:Connect(function(plr, towerCFrame)
	local mouse = plr:GetMouse()
	local tower = game.ReplicatedStorage.Towers.Part:Clone()
	tower.Parent = workspace
	tower.Anchored = true
	tower.Position = towerCFrame
end)

No error message.

ur making a new inputbegan connection every RenderStepped event

Loop doesn’t needed for uis, replace function in the top of script.

UIS.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
PlaceEvent:FireServer(part.CFrame.p)
part:Destroy()
placeRSF:Disconnect()
end
end)

button.MouseButton1Down:Connect(function()
local part = game.ReplicatedStorage.Towers.Part:Clone()
part.Parent = workspace
placeRSF = RS.RenderStepped:Connect(function()
part.Position = mouse.Hit.p
end)
end)

you also will need to add checking:

UIS.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if placeRSF == nil then return end
PlaceEvent:FireServer(part.CFrame.p)
part:Destroy()
placeRSF:Disconnect()
end
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.