Hello!
I’ve made a script to delete blocks when tapped in my building game, but it thinks swipe gestures, like to move the camera, are taps, which deletes the blocks.
The blocks are only deleted when the swipe gesture starts on the block.
Here’s a part of my script that I think is relevant:
ClickConnection = UserInputService.InputBegan:Connect(function(input)
if deleteMode.Value == true then
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
local mousePosition = UserInputService:GetMouseLocation()
DestroyBlockRemote:FireServer(CurrentCamera:ViewportPointToRay(mousePosition.X, mousePosition.Y))
end
end
end)
Here's a video of this (using Studio's mobile emulator)
Here's the full script
-- References
local LocalPlayer = game:GetService("Players").LocalPlayer
local BuildGui = LocalPlayer:WaitForChild("PlayerGui", 60):WaitForChild("BuildGui", 60)
local Button = script.Parent
local UserInputService = game:GetService("UserInputService")
local CurrentCamera = game.Workspace.CurrentCamera
local TweenService = game:GetService("TweenService")
-- Remotes
local DestroyBlockRemote = game:GetService("ReplicatedStorage").Remotes.Building.DestroyBlock
local TimeTypeRemote = game.ReplicatedStorage.TimeType -- sends TimeType when match starts, 3 == end, 2 == start, 1 == intermission.
-- Variables
local ClickConnection
-- cool code :smiling_sunglasses:
local deleteMode = script.Parent.Parent.deleteMode
deleteModeConnection = Button.Activated:Connect(function()
deleteMode.Value = not deleteMode.Value
local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Exponential)
if deleteMode.Value == false then
local tween = TweenService:Create(Button, tweenInfo, {
BackgroundColor3 = Color3.fromRGB(125, 19, 19),
TextTransparency = 0.25,
BackgroundTransparency = 0.4
})
tween:Play()
Button.Text = "<i>delete mode</i>"
else
local tween = TweenService:Create(Button, tweenInfo, {
BackgroundColor3 = Color3.fromRGB(197, 70, 70),
TextTransparency = 0,
BackgroundTransparency = 0
})
tween:Play()
Button.Text = "delete mode"
end
end)
TimeTypeRemote.OnClientEvent:Connect(function(timeType)
if timeType[2] == 3 then
if ClickConnection then
ClickConnection:Disconnect()
end
ClickConnection = UserInputService.InputBegan:Connect(function(input)
if deleteMode.Value == true then
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
local mousePosition = UserInputService:GetMouseLocation()
DestroyBlockRemote:FireServer(CurrentCamera:ViewportPointToRay(mousePosition.X, mousePosition.Y))
end
end
end)
else
if ClickConnection then
ClickConnection:Disconnect()
end
end
end)