I've been learning about ContextActionService
and I need to pass to the function (In this case the binded function) some arguements
Here's the code
--LocalScript local player = game.Players.LocalPlayer local tool = script.Parent local cas = game:GetService("ContextActionService") local actionName = "openDoor" function openDoor(slot) --This needs the slot variable slot.Value:WaitForChild("Open"):FireServer() tool:WaitForChild("Slot"):Destroy() slot.Value = nil cas:UnbindAction(actionName) end while true do local slot = tool:FindFirstChild("Slot") if slot and slot.Value ~= nil then cas:BindAction(actionName, openDoor(slot), false, "f") --IMPORTANT end wait(0.5) end
also it gives me an error,
Arguement 2 missing or nil: line 21
If you still don't understand, feel free to ask and I'll elaborate.
-- open door function function openDoor(slot,action,state,input) --This needs the slot variable slot.Value:WaitForChild("Open"):FireServer() tool:WaitForChild("Slot"):Destroy() slot.Value = nil cas:UnbindAction(actionName) end -- bind cas:BindAction(actionName, function(action,state,input) openDoor(slot,action,state,input) end, false, Enum.KeyCode.F) --IMPORTANT
Alright I fixed it... I just made the variable slot
into a global variable instead of just being inside the while loop
so the whole code looks like this now
local player = game.Players.LocalPlayer local tool = script.Parent local cas = game:GetService("ContextActionService") local actionName = "openDoor" local slot --This is global now function openDoor() slot.Value:WaitForChild("Open"):FireServer() tool:WaitForChild("Slot"):Destroy() slot = nil cas:UnbindAction(actionName) end while true do slot = tool:FindFirstChild("Slot") if slot and slot.Value ~= nil then cas:BindAction(actionName, openDoor, false, "f") end wait(0.5) end