Im making a mounted sniper, not a tool so i want it to move good when scoped but it doesnt move much and glitches no errors, but in third person it works fine. Any ideas on how to do this? also im planning in adding clamping to the rotation. its supposed to follow the mouse is there a better way to do this?
robloxapp-20250125-1207358.wmv (1.8 MB)
–Server side
local Prompt = script.Parent
local Allowed = game.Workspace.Guards.Triangle
local Configs = script.Parent.Parent.Parent.SniperConfigs
local Model = script.Parent.Parent.Parent
local events = game.ReplicatedStorage.ShapeGame.Events.GRLightEvents
task.wait(0.1)
Configs.OriginalOrientation.Value = Model.Gun.PrimaryPart.Orientation
local OriginalOrientation = Configs.OriginalOrientation.Value
local Limits = Configs.Limits
local PlayerVal = Configs.Owner
local PlayerNameAssignedToOnly = Configs.PlayerAssignedName
local AssignedAlready = false
Prompt.Triggered:Connect(function(player:Player)
if player.Character.Parent ~= Allowed then return end -- and add, and player.Name ~= PlayerNameAssignedToOnly.Value
print("Yep Perfect sending event to player to then use the sniper")
PlayerVal = PlayerVal
events.TriangleGuard.RequestAndUseSniper:FireClient(player,"BindSniper",Model.Gun.ImportantParts.ScopeCamera,Model)
AssignedAlready = true
player.Character.Humanoid.Died:Once(function()
PlayerVal.Value = nil
end)
end)
PlayerVal:GetPropertyChangedSignal("Value"):Connect(function()
if PlayerVal.Value ~= nil and PlayerVal.Value.Name == PlayerNameAssignedToOnly.Value and AssignedAlready == true then
AssignedAlready = false
end
end)
events.TriangleGuard.SniperTurnTo.OnServerInvoke = function(player:Player,SniperMovementText,mousePos,snipermodel:Model,ScopedVal)
--print("firing thing")
local ScopeSuccessful = false
-- print(ScopedVal)
--print(player.Name.." , "..SniperMovementText.." , "..snipermodel.Name)
if player.Character.Parent ~= Allowed then
events.TriangleGuard.SniperTurnTo:InvokeClient(player, "UnbindSniper")
-- print("DONT PASS")
else
-- print("pass")
end
print("pass")
if SniperMovementText == "ShootSniper" then
elseif SniperMovementText == "StopSniper" then
end
if SniperMovementText == "MoveSniper" then
local Part2Move = snipermodel.Gun.PrimaryPart
--print(Part2Move.Name)
-- print("moving")
--local look_at_rotation = CFrame.lookAt(Model.Gun.ImportantParts.ScopeCamera.Position, mousePos)
Part2Move.CFrame = CFrame.new(Part2Move.Position,mousePos)
--print(mousePos)
if ScopedVal == true then
ScopeSuccessful = true
end
end
return ScopeSuccessful
end
--coroutine.resume(coroutine.create(function()
-- while task.wait(0.01) do
-- end
--end))
function Shoot(player:Player,model:Model)
if player.Character.Parent ~= Allowed then return end
end
once i add the roles it should use some variables.
--Client side
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SniperEvent = ReplicatedStorage:WaitForChild("ShapeGame").Events.GRLightEvents.TriangleGuard.RequestAndUseSniper
local SniperTurnTo = ReplicatedStorage:WaitForChild("ShapeGame").Events.GRLightEvents.TriangleGuard.SniperTurnTo
local RS = game:GetService("RunService")
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local camera = workspace.CurrentCamera
local uis = game:GetService("UserInputService")
local context = game:GetService("ContextActionService")
--Vals
local SniperModel = nil
local CD = 5
local me = false
local Scoped = false
local move = false
local event = nil
local CDDEB = false
local cam = nil
local moving = false
--trigger
SniperEvent.OnClientEvent:Connect(function(argument,CAM,Sniper)
if argument == "BindSniper" then
event = SniperTurnTo
SniperModel = Sniper
cam = CAM
me = true
context:BindActionAtPriority("MouseFollow",MoveCamera,false,5,Enum.UserInputType.MouseMovement)
move = true
--Scoped = true
elseif argument == "UnbindSniper" then
me = false
move = false
camera.CameraType = Enum.CameraType.Custom
cam = nil
event = nil
context:UnbindAction("MouseFollow")
end
end)
mouse.Button1Down:Connect(function()
if me then
if event == nil and SniperModel == nil then return end
event:InvokeServer("ShootSniper",SniperModel)
move = true
end
end)
--mouse.Button1Up:Connect(function()
-- if me then
-- if event == nil and SniperModel == nil then return end
-- event:FireServer("StopSniper",SniperModel)
-- move = false
-- end
--end)
uis.InputBegan:Connect(function(input, gameprocessed)
if not gameprocessed and input.KeyCode == Enum.KeyCode.C then
if Scoped == false and cam ~= nil then
Scoped = true
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = cam.CFrame
--player.CameraMode = Enum.CameraMode.LockFirstPerson
camera.FieldOfView = 30
elseif Scoped == true then
Scoped = false
-- player.CameraMode = Enum.CameraMode.Classic
camera.FieldOfView = 70
camera.CameraType = Enum.CameraType.Custom
end
end
end)
function MoveCamera(ActionName)
print("func received")
if ActionName ~= "MouseFollow" and SniperModel == nil then return end
print("follow")
print("move") local scopesuccess = event:InvokeServer("MoveSniper", mouse.Hit.Position,SniperModel,Scoped)
if scopesuccess then
camera.CFrame = cam.CFrame
print("Cam")
else
print("nah")
end
end