-
What do you want to achieve? Keep it simple and clear!
i just want, for the GUI To appear when the player is in mobile. -
What is the issue? Include screenshots / videos if possible!
Thing is, the first time i tried i thought it would work, it did not. i thought it would be a problem within “SetDevicePref” but i dont know. i added print statements inside SetDevicePref and Tool.Equipped but they arent printing. now im just terribly confused. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
i tried Firing SetDevicePref for when Mousebutton2 is held, to see if it would print. still a no. i tried searching through out the Devforum but alot of them i already tried and or not a error to my code.
For Some reason, the equip animation and setting Equipped to true still works. but setting it’s parent and firing SetDevicePref doesnt work.
i also removed alot of code just to see if they could be the source of the problem. turns out they werent. and lost a bunch of code.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local Tool = script.Parent
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local TweenService = game.TweenService
local Cam = workspace.CurrentCamera
local servergun = Tool:WaitForChild("servergun")
local Cooldown = servergun.ShotCooldown
local Shoot = servergun:WaitForChild(Tool.Name .. "shoot")
local Reload = servergun:WaitForChild(Tool.Name .. "reload")
local Ammo = servergun:WaitForChild("Ammo")
local PlayerGUI = player.PlayerGui
local GUI
local Crosshair = PlayerGUI:WaitForChild("CrosshairGUI"):WaitForChild("Center")
local ShootAnimation = script:WaitForChild("Shoot")
local equipAnimation = script:WaitForChild("Equip")
local ReloadAnimation = script:WaitForChild("Reload")
local holdAimAnimation = script:WaitForChild("Hold")
local PlayerModule
local shootTrack = hum:LoadAnimation(ShootAnimation)
local equipTrack = hum:LoadAnimation(equipAnimation)
local ReloadTrack = hum:LoadAnimation(ReloadAnimation)
local holdAimTrack = hum:LoadAnimation(holdAimAnimation)
local TweenZoom = TweenService:Create(Cam, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {FieldOfView = 30})
local TweenZoomOut = TweenService:Create(Cam, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {FieldOfView = 70})
local mouse = player:GetMouse()
local UIS = game.UserInputService
local Equipped = false
local Aim = false
local CanShoot = true
local reloading = false
local function SetGripProperties(position, orientation)
if Tool:IsA("Tool") then
Tool.Grip = CFrame.new(position) * CFrame.Angles(math.rad(orientation.x), math.rad(orientation.y), math.rad(orientation.z))
end
end
local function SetDevicePref()
print("IsSettings")
if not UIS.TouchEnabled and (UIS.KeyboardEnabled or UIS.MouseEnabled) then
print("IsDesktop")
UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
PlayerModule = require(player:WaitForChild("PlayerScripts", math.huge):WaitForChild("PlayerModule"))
elseif UIS.TouchEnabled and not UIS.KeyboardEnabled and not UIS.MouseEnabled then
print("IsMobile")
GUI = game.ReplicatedStorage:WaitForChild("GunGUI"):Clone()
GUI.Parent = PlayerGUI
end
end
Tool.Equipped:Connect(function()
script.Parent = player
print("Equipped")
SetDevicePref()
equipTrack:Play()
Equipped = true
end)
local function CameraFOV()
if PlayerModule then
PlayerModule:ToggleShiftLock(false, true, true)
end
TweenZoom:Play()
mouse.Icon = "rbxassetid://15722065980"
print("CameraChange")
end
local function ResetCameraFOV()
mouse.Icon = "rbxasset://SystemCursors/Arrow"
TweenZoomOut:Play()
print("CameraChange")
end
local function ReloadFunction()
reloading = true
ReloadTrack:Play()
Reload:FireServer()
ResetCameraFOV()
if UIS.KeyboardEnabled then
UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
end
Aim = false
holdAimTrack:Stop()
equipTrack:Play()
PlayerModule:ToggleShiftLock(true, true, true)
ReloadTrack.Stopped:Wait()
reloading = false
end
UIS.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton2 then
if Equipped then
CameraFOV()
if UIS.KeyboardEnabled then
UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
end
PlayerModule:ToggleShiftLock(false, true, true)
hum.WalkSpeed = 16
Aim = true
SetGripProperties(Vector3.new(0, 0, 0), Vector3.new(0, 6, 0))
equipTrack:Stop()
holdAimTrack:Play()
end
end
end)
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R then
print("pressed Reload Key")
if Equipped then
if not reloading then
print("Reloading")
ReloadFunction()
end
end
end
end)
Ammo:GetPropertyChangedSignal("Value"):Connect(function()
if Ammo.Value == 0 and not reloading then
ReloadFunction()
end
end)
UIS.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if Equipped then
if Aim then
if CanShoot then
print("shot")
CanShoot = false
Shoot:FireServer(Tool.Handle.CFrame.Position, mouse.Hit.p, char)
shootTrack:Play()
wait(Cooldown.Value)
CanShoot = true
end
end
end
end
end)
UIS.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton2 then
if Equipped then
ResetCameraFOV()
Aim = false
if UIS.KeyboardEnabled then
UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
end
holdAimTrack:Stop()
equipTrack:Play()
PlayerModule:ToggleShiftLock(true, true, true)
end
end
end)
hum:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
if hum.WalkSpeed == 25 then
if Aim and Equipped then
ResetCameraFOV()
Aim = false
holdAimTrack:Stop()
equipTrack:Play()
PlayerModule:ToggleShiftLock(true, true, true)
end
end
end)
Tool.Unequipped:Connect(function()
Aim = false
UIS.MouseBehavior = Enum.MouseBehavior.Default
ResetCameraFOV()
Equipped = false
holdAimTrack:Stop()
equipTrack:Stop()
PlayerModule:ToggleShiftLock(true, true, true)
script.Parent = Tool
if GUI then
GUI:Destroy()
end
end)