Hello! I hope your having a good day, if not I hope it gets better!
I’ve been making a viewmodel gun, it worked and all except the tool doesn’t show in the server it only shows to the client. The main script for it is local in starter gui. The other script is just placement for the gun in the hand. Im stuck on how I show it to the server.
Yeah, I used it from a yt tutorial. But I have another script which I discarded because I wanted to make a choose your weapon script.
repeat
wait()
until game:IsLoaded()
local plr = game.Players.LocalPlayer
local char = plr.Character
local mouse = plr:GetMouse()
local cam = workspace.CurrentCamera
local User = game:GetService("UserInputService")
local Run = game:GetService("RunService")
local RS = game.ReplicatedStorage
local GunModules = RS:WaitForChild("GunModules")
local GunModels = RS:WaitForChild("GunModels")
local Primary = "AK47"
local WeaponInHand
local LArm, RArm
local WeaponData
local aimming = false
local maincf = CFrame.new() --weapon offset of camera
local larmcf = CFrame.new() --left arm offset of weapon
local rarmcf = CFrame.new() --right arm offset of weapon
local aimcf = CFrame.new()
User.MouseIconEnabled = false
plr.CameraMode = Enum.CameraMode.LockFirstPerson
Run.RenderStepped:Connect(function()
if WeaponInHand and LArm and RArm then --Check if the weapon and arms are loaded
WeaponInHand:SetPrimaryPartCFrame(
cam.CFrame
* maincf
* aimcf
)
LArm:SetPrimaryPartCFrame(
WeaponInHand.PrimaryPart.CFrame
* larmcf
)
RArm:SetPrimaryPartCFrame(
WeaponInHand.PrimaryPart.CFrame
* rarmcf
)
if aimming then
aimcf = aimcf:Lerp(WeaponData.AimCFrame,0.2) --Goal CFrame (lower the number, lower the speed is)
else
aimcf = aimcf:Lerp(CFrame.new(), 0.1)
end
end
end)
function setup(weapon)
--setup weapon data module
WeaponData = require(GunModules:WaitForChild(weapon))
maincf = WeaponData.MainCFrame
larmcf = WeaponData.LArmCFrame
rarmcf = WeaponData.RArmCFrame
--setup arms to camera
LArm = RS:WaitForChild("Left Arm"):Clone()
LArm.PrimaryPart = LArm:WaitForChild("Main")
LArm.Parent = cam
for i, part in pairs(LArm:GetChildren()) do
if part:IsA("BasePart") then
part.Anchored = true --Make all the parts anchored so it wont fall off
part.CanCollide = false --make al the parts cant collide so the character wont fly
end
end
RArm = RS:WaitForChild("Right Arm"):Clone()
RArm.PrimaryPart = RArm:WaitForChild("Main")
RArm.Parent = cam
for i, part in pairs(RArm:GetChildren()) do
if part:IsA("BasePart") then
part.Anchored = true --Make all the parts anchored so it wont fall off
part.CanCollide = false --make al the parts cant collide so the character wont fly
end
end
--setup weapon to camera
WeaponInHand = GunModels:WaitForChild(weapon)
WeaponInHand.PrimaryPart = WeaponInHand:WaitForChild("Handle")
WeaponInHand.Parent = cam
for i, part in pairs(WeaponInHand:GetChildren()) do
if part:IsA("BasePart")then
part.Anchored = true --make all th parts anchored so it wont fall off
part.CanCollide = false --make all the parts can't collide so the charcter won't fly
end
end
end
mouse.Button2Down:Connect(function()
aimming = true
end)
mouse.Button2Up:Connect(function()
aimming = false
end)
setup(Primary)