You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
I’m trying to have a ray (Or gun bullet rather) shoot towards the middle of the player’s screen, which, with a shift lock script, changes position. I’m wondering if it’s possible to add an offset to where the script thinks is the middle of the screen.
Here’s some of my code:
The following is the client code, I’m assuming that’s where I’ll have to add the offset so it can be sent to the server already offset.
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if tool.Parent.Name == player.Name then
print("Im in le player")
local inputType = input.UserInputType
if inputType == Enum.UserInputType.Touch or inputType == Enum.UserInputType.MouseButton1 then
print("Began")
if debounce == false or debounce == nil then
local remoteEvent = script.Parent.Remotes:WaitForChild("~~RE Here~~")
-- Fire the remote event
--local camera = workspace.CurrentCamera
--local unitRay = camera:ScreenPointToRay(100, 100)
local camera = workspace.CurrentCamera
-- local viewportPoint = camera.ViewportSize / 2
local camlookvector = camera.CFrame.LookVector --camera:ViewportPointToRay(viewportPoint.X, viewportPoint.Y, 0)
-- local Players = game:GetService("Players")
--local localPlayer = Players.LocalPlayer
--local mouse = localPlayer:GetMouse()
--local unitRayDirection = mouse.UnitRay.Direction
--local mouseHitDirection = mouse.Hit.lookVector
local ShootFunction = script.Parent.Remotes:WaitForChild("~~RE Here~~")
-- if bulletsleft > 0 then
local be = script.Parent.Remotes:WaitForChild("~~RE Here~~")
be:Fire("ShootAnim")
-- Invoke the function
local Damage, BulletAmt, MagAmt = ShootFunction:InvokeServer(camlookvector)
print("damage done,", Damage, "Bullets Left,", BulletAmt, "Mags left,", MagAmt)
bulletsleft = BulletAmt
--remoteEvent:FireServer(unitRay)
--elseif bulletsleft == 0 then
-- warn("NO MORE")
--end
debounce = true
wait(.1)
debounce = false
else
print("Still waiting")
end
end
end
end)
I am using this script for an in-game shift lock effect, it’s not roblox’s but one that I used off of dev forum
--Local script in StarterPlayerCharacter
local plr = game:GetService("Players").LocalPlayer
local mouse = plr:GetMouse()
local char = plr.Character
local hum = char:WaitForChild("Humanoid")
---------------------------------------------------------
local rotation = Instance.new("BodyGyro") --Create a new body gyro.
rotation.P = 1000000 --Increase the power
rotation.Parent = hum.RootPart --Parent it to the HumanoidRootPart
---------------------------------------------------------
local conn -- connection variable
function shiftLock(active) --Toggle shift.lock function
if active then
hum.CameraOffset = Vector3.new(1,0.5,0) -- I assume this is about the right camera offset.
---------------------------------------------------------
rotation.MaxTorque = Vector3.new(0, math.huge, 0) --Max the power on the Y axis
---------------------------------------------------------
conn = game:GetService("RunService").RenderStepped:Connect(function()
rotation.CFrame = mouse.Origin
game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.LockCenter
end) --Set the mouse to center every frame.
else
hum.CameraOffset = Vector3.new(0,0,0) --Move the camera back to normal.
---------------------------------------------------------
rotation.MaxTorque = Vector3.new(0, 0, 0) --Clear the torque on the HumanoidRootPart
---------------------------------------------------------
if conn then conn:Disconnect() end -- Allow mouse to move freely.
end
end
--shiftLock(true) -- Enable shift lock
--print("Shift lock turned on!")
--[[
shiftLock(false) --Toggle off shift Lock
]]
I first thought of multiplying the camlookvector
by the offset (hum.CameraOffset = Vector3.new(1,0.5,0)
)
If anyone has advice please let me know asap, thanks and have a great day!