How to make a viewmodel script that works with CAS

the title says it all i need help with making viewmodel script thats gonna work with my current cas script. Here is the script:

local ContextActionService = game:GetService("ContextActionService")
local Player = game:FindFirstChild("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local humanoid = Character:WaitForChild("Humanoid")
local humanoidroot = Character:WaitForChild("HumanoidRootPart")
local Animator = humanoid:WaitForChild("Animator")
local idle = false
local equipped = false

local function FlashLight(actionName, inputState)
	if actionName == "PressedFlashLight" and inputState == Enum.UserInputState.Begin then
		if not idle then
			idle = true
			equipped = true
		else
			idle = false
			equipped = false
		end
	end
end

ContextActionService:BindAction("PressedFlashLight", FlashLight, true, Enum.KeyCode.F, Enum.KeyCode.ButtonY)
ContextActionService:setTitle("PressedFlashLight", "FlashLight")
ContextActionService:SetPosition("PressedFlashLight", UDim2.new(0.4, 0, 0.9, 0))
ContextActionService:SetImage("PressedFlashLight", "http://www.roblox.com/asset/?id=9657060536")

local Runbutton = ContextActionService:GetButton("PressedFlashLight")
if Runbutton then
	Runbutton.ImageColor3 = Color3.fromRGB(255, 247, 0)
end

the viewmodel name is flashviewmodel in ReplicatedStorage
thanks for ur helps!
(i dont know anything about viewmodel scripting)

2 Likes

Oh my eyes :sob: is this your script ? and Use the Preformatted text next time also can you provide the full script?

ok how can i do it i dont know it either😭


Press this buton and put your script inside it

oh ok i will do it now thanks.

EDIT: i did it. So, can you help me?

1 Like

hey its been like 35 minutes can you help me now?

Arent you reading ?!? I asked for the full script. Why are you even using ContextActionService ?

this is the full script . _ . and im using context action service for mobile support and console support it isn’t posbile with cas?

i just maked the script pure as just cas wil be remain so there is no other things except cas ig can you hep me to add viewmodel script to this i couldnt find any forum orvideo for the same problem so

It is tho not for mobile you can make extra functions for UI’s to make the same Thing, Can you send your viewmodel file so I can make it for that?

sure!
flashlightviewmodel.obj (1.2 MB)

its a skinned mesh btw ig this is not a problem

ig im wanting the help wrong way or the wrong thing

oof I was busy sorry for the wait let me work on it

I need the rigged model not the mesh tho I dont know how u want the thing to be. Since this is for helping and learning Im not able to do the rigging for you. But rigging is easy + the mesh have too many triangles that dont let me upload

uhhh i want when presed f the viewmodel will be cloned to camea and follows it whne pressed f again it will be destroyed but can you help me just clone a light part?

Alright kankacim anladık onu You need to rig the viewmodel how am I supposed to help while ur trying to not get help

sorry im really newbie but its rigged ig

I asked for the rig not the mesh but alright I need you to send me the Model

oh ok! Sorry i was sent you the obj
flashviewmodel.rbxm (104.7 KB)