I tried to make a script using context action service, but the function has a parameter, is there a way to get around this?
function openPhone(player) -- This is the function that will run local playerGui = player:WaitForChild("PlayerGui") local frame = playerGui.PhoneMenuGui.MainFrame frame:TweenPosition( UDim2.new(-0, 0, 0.262, 0), -- End position "Out", -- Easing direction "Bounce", -- Easing style 1, -- Time in seconds false, -- Overide other tweens print("Phone opened"), chooseGradient(player) ) end game.Players.PlayerAdded:Connect(function(player) local localPlayer = player if UserInputService.KeyboardEnabled then ContextActionService:BindAction("openAndTweenPhone", openPhone(localPlayer), false, "p") end end)
sure. in lua, you can always wrap it with an anonymous function when you get a parameter issue like this.
game.Players.PlayerAdded:Connect(function(player) local localPlayer = player if UserInputService.KeyboardEnabled then ContextActionService:BindAction( "openAndTweenPhone", function() openPhone(localPlayer) end, false, "p") end end)
remember, all ContextActionService needs is a function. any function. doing it like this, it executes the function on the outside without parameters, but ends up running the function on the inside using parameters from outside :)
in fact, you're already doing it when you write game.Players.PlayerAdded:Connect(function(player) ... end)