Yup, that’s my problem. Pressing 1 will not do anything.
Script (For pressing 2) (See lines 85-97 and 135):
local rs = game:GetService("ReplicatedStorage")
local runservice = game:GetService("RunService")
local uis = game:GetService("UserInputService")
local button = script.Parent
local placetowerbutton = script.Parent.Parent:WaitForChild("PlaceTower")
local towersfold = rs:WaitForChild("TDTowers")
local foundName = (button:WaitForChild("Tower")).Value
local collisionsmod = require(rs:WaitForChild("Collisions"))
local clickedonce = script.Parent.Parent.Parent:WaitForChild("IsPlacingTower")
local canPlace = true
local spawna = rs:WaitForChild("SpawnTower")
local towerslotplacing = script.Parent.Parent.Parent:WaitForChild("TowerSlotPlacing")
local replaceTower1 = (script.Parent.Parent:WaitForChild("Slot1Button")):WaitForChild("ReplaceTower1")
local replaceTower2 = script.Parent:WaitForChild("ReplaceTower2")
local errorframe = script.Parent.Parent.Parent:WaitForChild("ErrorFrame")
local worktowerfold = game.Workspace:WaitForChild("Towers")
local camera = game.Workspace.CurrentCamera
local accessories = {}
local accessorynames = {}
local placedesc
local skincolor
local getcast
local place
local lastplacetapped
local function castmouse()
local castpar = RaycastParams.new()
castpar.FilterType = Enum.RaycastFilterType.Blacklist
castpar.FilterDescendantsInstances = place:GetDescendants()
local mousepos = uis:GetMouseLocation()
local raymouse = camera:ViewportPointToRay(mousepos.X, mousepos.Y)
local result = game.Workspace:Raycast(raymouse.Origin, raymouse.Direction * 1000)
return result
end
local function casttap(touchpos, togetdesc)
local castpar = RaycastParams.new()
castpar.FilterType = Enum.RaycastFilterType.Blacklist
castpar.FilterDescendantsInstances = togetdesc:GetDescendants()
local raytap = camera:ViewportPointToRay(touchpos.X, touchpos.Y)
local result = game.Workspace:Raycast(raytap.Origin, raytap.Direction * 1000)
return result
end
uis.TouchTapInWorld:Connect(function(tappedplace)
if place ~= nil then
lastplacetapped = tappedplace
print(tappedplace)
print(place)
getcast = casttap(tappedplace, place)
local x = getcast.Position.X
local y = getcast.Position.Y +(place.PrimaryPart.Size.Y) / 2 + place["Left Leg"].Size.Y
local z = getcast.Position.Z
local placecframe = CFrame.new(x, y, z)
local primpart = place.PrimaryPart
local orientationX, orientationY, orientationZ = primpart.CFrame.Rotation:ToOrientation()
place:SetPrimaryPartCFrame(placecframe * CFrame.fromOrientation(orientationX, orientationY, orientationZ))
else
lastplacetapped = tappedplace
end
end)
local function initplacetower()
local tower = towersfold:FindFirstChild(foundName)
if tower then
place = tower:Clone()
place.Parent = worktowerfold
placedesc = place:GetDescendants()
for i, v in pairs(placedesc) do
if v:IsA("MeshPart") then
table.insert(accessorynames, v.Name)
table.insert(accessories, v.TextureId)
elseif v:FindFirstChild("Mesh") then
table.insert(accessorynames, v.Name)
table.insert(accessories, v.Mesh.TextureId)
end
end
skincolor = (place:WaitForChild("Head")).Color
local placedesc = place:GetDescendants()
collisionsmod.SetPartToGroup(placedesc, "Towers & Monsters")
end
end
local function placetower() --Stop here,
if clickedonce.Value == false then
towerslotplacing.Value = 2
initplacetower()
clickedonce.Value = true
elseif clickedonce.Value == true then
if towerslotplacing.Value == 1 then
towerslotplacing.Value = 2
replaceTower2:Fire()
initplacetower()
end
end
end
button.MouseButton1Click:Connect(function()
placetower()
end)
runservice.RenderStepped:Connect(function()
if place ~= nil then
local castpar = RaycastParams.new()
castpar.FilterType = Enum.RaycastFilterType.Blacklist
castpar.FilterDescendantsInstances = place:GetDescendants()
if uis.KeyboardEnabled == true and uis.MouseEnabled == true then --Mouse
getcast = castmouse()
elseif uis.KeyboardEnabled == true and uis.TouchEnabled == true and uis.MouseEnabled == false then --Touch
getcast = casttap(lastplacetapped, place)
elseif uis.TouchEnabled == true and uis.MouseEnabled == true then --Touch/Mouse
getcast = castmouse()
end
if getcast and getcast.Instance then
if getcast.Instance.Name ~= "CanPlaceOn" then
canPlace = false
else
canPlace = true
end
local x = getcast.Position.X
local y = getcast.Position.Y +(place.PrimaryPart.Size.Y) / 2 + place["Left Leg"].Size.Y
local z = getcast.Position.Z
local placecframe = CFrame.new(x, y, z)
local primpart = place.PrimaryPart
local orientationX, orientationY, orientationZ = primpart.CFrame.Rotation:ToOrientation()
place:SetPrimaryPartCFrame(placecframe * CFrame.fromOrientation(orientationX, orientationY, orientationZ))
end
end
end)
uis.InputBegan:Connect(function(input, processed)
if input.KeyCode == Enum.KeyCode.R then
place:SetPrimaryPartCFrame(place.PrimaryPart.CFrame * CFrame.Angles(0, math.pi/2, 0))
elseif input.KeyCode == Enum.KeyCode.Two then --And here
placetower()
elseif input.KeyCode == Enum.KeyCode.Backspace or input.KeyCode == Enum.KeyCode.Delete then
place:Destroy()
place = nil
clickedonce.Value = false
end
end)
uis.InputBegan:Connect(function(input, processed)
if input.KeyCode == Enum.KeyCode.E then
if canPlace == true then
if clickedonce.Value == true then
print(place.Name)
spawna:FireServer(place.Name, place.PrimaryPart.CFrame)
task.wait()
place:Destroy()
place = nil
clickedonce.Value = false
end
else
errorframe.BackgroundTransparency = 0.75
local errortext = errorframe:WaitForChild("TextLabel")
errortext.Text = "Cannot place here!"
errortext.TextTransparency = 0
task.wait(1)
errorframe.BackgroundTransparency = 1
errortext.TextTransparency = 1
end
end
end)
placetowerbutton.TouchTap:Connect(function()
if canPlace == true then
if clickedonce.Value == true then
spawna:FireServer(place.Name, place.PrimaryPart.CFrame)
place:Destroy()
place = nil
clickedonce.Value = false
end
else
errorframe.BackgroundTransparency = 0.75
local errortext = errorframe:WaitForChild("TextLabel")
errortext.Text = "Cannot place here!"
errortext.TextTransparency = 0
task.wait(1)
errorframe.BackgroundTransparency = 1
errortext.TextTransparency = 1
end
end)
placetowerbutton.MouseButton1Click:Connect(function()
if canPlace == true then
if clickedonce.Value == true then
spawna:FireServer(place.Name, place.PrimaryPart.CFrame)
place:Destroy()
place = nil
clickedonce.Value = false
end
else
errorframe.BackgroundTransparency = 0.75
local errortext = errorframe:WaitForChild("TextLabel")
errortext.Text = "Cannot place here!"
errortext.TextTransparency = 0
task.wait(1)
errorframe.BackgroundTransparency = 1
errortext.TextTransparency = 1
end
end)
replaceTower2.Event:Connect(function()
place:Destroy()
task.wait()
place = nil
end)
(Putting the whole script, I’m not taking any chances in what is wrong)
What is happening? Even I’m confused, my script is really messy