Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Mouse.Hit.p not functioning with Mobile?

Asked by
MattVSNNL 620 Moderation Voter
3 years ago

I'm making a gun for my game and in my local script where I detected it shooting when a player taps, No errors, Can anyone help?

Client:

UIS.InputBegan:Connect(function(input, gameProcessedEvent)
    if input.UserInputType == Enum.UserInputType.Touch then
        if debounce == false then

            debounce = true

            script.Parent:FindFirstChild("Shoot"):FireServer(mouse.Hit.p)

            wait(5)

            debounce = false

        end
    end
end)

Server:

local debris = game:GetService("Debris")
local gun = script.Parent

local shootRE = gun:FindFirstChild("Shoot")

shootRE.OnServerEvent:Connect(function(player, mousePos)

    gun:FindFirstChild("Handle"):FindFirstChild("GunShot"):Play()

    local raycastParams = RaycastParams.new()
    raycastParams.FilterDescendantsInstances = {player.Character}
    raycastParams.FilterType = Enum.RaycastFilterType.Blacklist

    local raycastResult = workspace:Raycast(gun:FindFirstChild("Handle").Position, (mousePos - gun:FindFirstChild("Handle").Position) * 300, raycastParams) 

    if raycastResult then

        local hitPart = raycastResult.Instance
        local model = hitPart:FindFirstAncestorOfClass("Model")

        if model then
            if model:FindFirstChild("Humanoid") then
                model:FindFirstChild("Humanoid"):TakeDamage(100)
            end
        end

    end

    local cloneBullet = Instance.new("Part")
    cloneBullet.Shape = "Ball"
    cloneBullet.Size = Vector3.new(0.218, 0.218, 0.218)
    cloneBullet.Material = Enum.Material.Metal
    cloneBullet.Transparency = 0.5
    cloneBullet.Name = "Bullet"
    cloneBullet.Position = mousePos
    cloneBullet.Anchored = true
    cloneBullet.Parent = workspace

    gun:FindFirstChild("Handle"):FindFirstChild("Reload"):Play()

    wait(5)

    cloneBullet:Destroy()

end)
0
nvm I fixed it MattVSNNL 620 — 3y

Answer this question