I'm having this weird problem that i've never seen

as i said i’m having this weird problem that i’ve never seen before

when replicating a flashlight from replicated storage into the player even though the can collide is off the player really fastly jerks down and then back up i have a video if that didnt make since

robloxapp-20230205-1328202.wmv (3.0 MB)

heres the server script

game.ReplicatedStorage.EventStorage.FlashlightEvents.on.OnServerEvent:Connect(function(plr:Player)

local clone = game.ReplicatedStorage.VmStorage.FakeFlashlight:Clone()

clone.Parent = plr.Character

print(clone.Parent)

local head = plr.Character:WaitForChild(“Head”)

clone.PrimaryPart.CFrame = head.CFrame * CFrame.new(0.9,0.35,-0.2)

local weld = Instance.new(“WeldConstraint”)

weld.Parent = plr.Character

weld.Part0 = clone.PrimaryPart

weld.Part1 = plr.Character.HumanoidRootPart

clone.PrimaryPart.CFrame = plr.Character.HumanoidRootPart.CFrame

print(“Cewl”)

end)

local script

local player = game.Players.LocalPlayer
local char = player.Character
local cam = workspace.CurrentCamera
local viewmodel = game.ReplicatedStorage.VmStorage:WaitForChild(“Flashlight”):Clone() or game.ReplicatedStorage.VmStorage.Flashlight:Clone() – just incase it’s already loaded
viewmodel.Parent = game.ReplicatedStorage.VmStorage[“ClonedVm’s”]
local run = game:GetService(“RunService”)
local CameraCF = CFrame.new()
local swayCF = CFrame.new()
local SwayX = 3
local SwayY = 5
local equip = game.ReplicatedStorage.BoolStorage.Flashlight
local uis = game:GetService(“UserInputService”)
task.wait()
local audio = script[“Flashlight Click”]
uis.InputBegan:Connect(function(inp)
if inp.KeyCode == Enum.KeyCode.F then
flashlight()
end
end)

function flashlight()
local val = game.ReplicatedStorage.BoolStorage.StartupGui.InGui
if val.Value == false then
if equip.Value == false then
game.ReplicatedStorage.EventStorage.FlashlightEvents.on:FireServer()
changeIfSwitch()
viewmodel.Handle[“Right Arm”].Color = game.Players.LocalPlayer.Character:WaitForChild(“Right Arm”).Color
viewmodel.Parent = cam
game.Players.LocalPlayer.Character:WaitForChild(“Right Arm”).Transparency = 1
audio:Play()
equip.Value = true
run.RenderStepped:Connect(function()
if game.Players.LocalPlayer.Character:WaitForChild(“Humanoid”).Health > 0 then
local rotation = workspace.CurrentCamera.CFrame:toObjectSpace(CameraCF)
local x,y,z = rotation:ToOrientation()
swayCF = swayCF:Lerp(CFrame.new(math.sin(-y)*SwayX,math.sin(x)*SwayY,0), .2)
CameraCF = cam.CFrame
– viewmodel.PrimaryPart.Position = game.Players.LocalPlayer.Character:WaitForChild(“Torso”).Position * CFrame
viewmodel:SetPrimaryPartCFrame(player.Character:WaitForChild(“Head”).CFrame * CFrame.new(CameraCF.Rotation.X,CameraCF.Rotation.Y,CameraCF.Rotation.Z) * CFrame.new(-0.6,-0.4,0.7)*swayCF)
end
end)
else
game.ReplicatedStorage.EventStorage.FlashlightEvents.off:FireServer()
equip.Value = false
viewmodel.Parent = game.ReplicatedStorage.VmStorage[“ClonedVm’s”]
game.Players.LocalPlayer.Character:WaitForChild(“Right Arm”).Transparency = 0
audio:Play()
end
end
end

function hideFlashlightIfDead()
if game.Players.LocalPlayer.Character:WaitForChild(“Humanoid”).Health <= 0 then
equip.Value = false
viewmodel.Parent = game.ReplicatedStorage.VmStorage[“ClonedVm’s”]
game.Players.LocalPlayer.Character:WaitForChild(“Right Arm”).Transparency = 0
end
end

function changeIfSwitch()
if game.ReplicatedStorage.BoolStorage.ThirdPerson.Switch.Value == true then
SwayX = 1
else
SwayX = 2.5
end
end

sorry i dont know how to use the format thing lol

you weld the part to the character before you move it. So when you change the cframe of the flashlight, you also move the character with it. Try changing the cframe of the clone first, then weld it to the humanoid root part

1 Like

You use Backticks which are these: ```
If you need Help locating it
So it would look like this:

-- This is code block

This is not a Code Block, This is preformatted text

This is not a Code Block, This is a Block Quote.

Plus, when creating a Topic, It Automatically provides you with a Code Block and its backtick format so I’m not sure how you are missing that one.

1 Like

that sorta fixed the problem but now its in the stomach of the player instead of the offset i set it as

thats because you set its cframe to humanoid root part. if you dont want it there then remove that line entirely

clone.PrimaryPart.CFrame = plr.Character.HumanoidRootPart.CFrame
(remove this one)

1 Like

Thanks for the help works like a charm

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.