Whenever i try launch a game and set current camera CFrame it’s just floats up or bouncing against the ground
-
What do i want to achieve? I need to fix the issue related to SetPrimeryPartCFrame on viewmodel
-
What’s going on with the camera?
-
What solutions have i tried so far?: I tried anchoring/unanchoring, changing colision and etc.
There is examples of scripts and then viewmodel in explorer picture.
MODULE SCRIPT
local GunScript = {}
local RunService = game:GetService("RunService")
function GunScript:GetTool(Which, ToWhichChar)
local ToolObj = Instance.new("StringValue")
ToolObj.Name = game:GetService("ReplicatedStorage").GunStorage:FindFirstChild(Which).Name
ToolObj.Value = game:GetService("ReplicatedStorage").GunStorage:FindFirstChild(Which).Name
ToolObj.Parent = ToWhichChar
end
function GunScript:EquipTool(Which)
return coroutine.create(function()
local plr = game.Players.LocalPlayer
local plrcam = workspace.CurrentCamera
local char = plr.Character or plr.CharacterAdded:Wait()
if char:FindFirstChild(Which) then
local Rightweapon = game:GetService("ReplicatedStorage").GunStorage:FindFirstChild(Which):Clone()
if Rightweapon then
Rightweapon.Parent = plr.Character or plr.CharacterAdded:Wait()
RunService.RenderStepped:Connect(function()
if Rightweapon.PrimaryPart then
Rightweapon:SetPrimaryPartCFrame(plrcam.CFrame)
end
end)
end
else
warn(plr.." Doesn't have a called weapon!")
end
end)
end
return GunScript
LOCAL SCRIPT
local Players = game:GetService("Players")
local CurrentGun = nil
local Holding = false
local GunScript = require(game:GetService("ReplicatedStorage").GunSystem:WaitForChild("GunScript"))
local plr = game.Players.LocalPlayer
local UIP = game:GetService("UserInputService")
local TS = game:GetService("TweenService")
local function UnEquipWeapon(Which)
local char = plr.Character or plr.CharacterAdded:Wait()
char:FindFirstChild(Which):Destroy()
end
UIP.InputBegan:Connect(function(InputObject, gameProcessedEvent)
if gameProcessedEvent then return end
if InputObject.KeyCode == Enum.KeyCode.One then
if Holding == false then
Holding = true
CurrentGun = GunScript:EquipTool("SMG")
coroutine.resume(CurrentGun)
else
Holding = false
coroutine.close(CurrentGun)
UnEquipWeapon("SMG")
end
end
end)
VIEWMODEL IN EXPLORER
Thank to anyone who will help me!
P.S. Module script Setup is just a parameters.