Hello!
I came across an issue where ROBLOX events just didn’t work after I tried to implement mobile/console support for my building system.
- I looked up solutions on the developer forum and tried to remove console support/mobile support and nothing worked. The button1down event just does not run.
local getDevice = require(game.ReplicatedStorage.modules.config.device)
local uis = game:GetService("UserInputService")
return function ()
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local event = game.ReplicatedStorage.events.hammer
local mouse = plr:GetMouse()
local holding = false
local pos1
local pos2
local plank
local function unconnect()
holding = false
pos1 = nil
pos2 = nil
if plank then
plank:Destroy()
plank = nil
end
end
local function register()
char:WaitForChild("Humanoid").Died:Connect(unconnect)
char.ChildAdded:Connect(function(Child)
if Child.Name == "hammer" and Child:IsA("Tool") then
local buttondown
local buttonup
local move
local function buttondownfunc()
if Child.Parent == char and char:WaitForChild("Humanoid").Health > 0 then
pos1 = mouse.Hit.Position
pos2 = nil
holding = true
end
end
local function buttonupfunc()
if Child.Parent == char and char:WaitForChild("Humanoid").Health > 0 and holding then
holding = false
pos2 = mouse.Hit.Position
if plank then
if plank.Size.Z > 15 or plank.Size.Z < 0.1 or (plank.Position - char.PrimaryPart.Position).Magnitude > 15 then
plank:Destroy()
elseif plank.Size.Z <= 15 and plank.Size.Z >= 0.1 and (plank.Position - char.PrimaryPart.Position).Magnitude <= 15 then
event:FireServer(plank.CFrame, plank.Size, Child)
plank:Destroy()
end
plank = nil
end
pos1 = nil
pos2 = nil
end
end
local function mousemove()
if holding == true and pos1 then
pos2 = mouse.Hit.Position
if not plank then
plank = Instance.new("Part")
plank.Parent = workspace
plank.Anchored = true
plank.CanQuery = false
plank.CanCollide = false
plank.Transparency = 0.5
plank.CanTouch = false
plank.Color = Color3.new(1,1,1)
end
if plank and pos2 then
plank.CFrame = CFrame.new((pos1 + pos2)/2, pos1)
plank.Size = Vector3.new(2, 2, (pos2-pos1).Magnitude)
if plank.Size.Z > 15 or plank.Size.Z < 0.1 or (plank.Position - char.PrimaryPart.Position).Magnitude > 15 then
plank.Color = Color3.new(1,0,0)
elseif plank.Size.Z <= 15 and plank.Size.Z >= 0.1 and (plank.Position - char.PrimaryPart.Position).Magnitude <= 15 then
plank.Color = Color3.new(1,1,1)
end
end
end
end
if getDevice.PC() == true then
buttondown = mouse.Button1Down:Connect(function()
buttondownfunc()
end)
buttonup = mouse.Button1Up:Connect(function()
buttonupfunc()
end)
move = mouse.Move:Connect(function()
mousemove()
end)
elseif getDevice.Mobile() == true then
buttondown = uis.TouchStarted:Connect(function()
buttondownfunc()
end)
buttonup = uis.TouchEnded:Connect(function()
buttonupfunc()
end)
move = uis.TouchMoved:Connect(function()
mousemove()
end)
elseif getDevice.Console() == true then
buttondown = uis.InputBegan:Connect(function(input, processed)
if not processed and input.KeyCode == Enum.KeyCode.ButtonR2 then
buttondownfunc()
end
end)
buttonup = uis.InputEnded:Connect(function(input, processed)
if not processed and input.KeyCode == Enum.KeyCode.ButtonR2 then
buttonupfunc()
end
end)
move = mouse.Move:Connect(function()
mousemove()
end)
end
Child:GetPropertyChangedSignal("Parent"):Once(function()
buttondown:Disconnect()
buttonup:Disconnect()
move:Disconnect()
unconnect()
end)
end
end)
end
plr.CharacterAdded:Connect(function(newChar)
char = newChar
register()
end)
register()
end
If you have any questions, let me know!