Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Does ContextAction Service have problems ingame?

Asked by 8 years ago

e.e. This works perfectly in studios however it isnt working in game. Can anyone help me figure out the problem because I got none.

--DONT TAKE THIS I WILL KILL YOU
--Credit to Angels_Develop for this Roll Ball
--if this is not currently in starterpack then please place it in it.
local plr = game.Players.LocalPlayer
local cam = game.Workspace.CurrentCamera
local UserInput = game:GetService('UserInputService')
local ContextActionService = game:GetService('ContextActionService')
local maxed = 100
repeat wait() until plr.Character and plr.Character.Humanoid
plr.Character:Destroy()
--Ball Stuff down here v
local ball = Instance.new("Part", workspace)
ball.Name = "Ball " .. plr.Name
ball.Transparency = 0.5
ball.Material = Enum.Material.Metal
ball.BrickColor = BrickColor.Random()
ball.Shape = Enum.PartType.Ball
ball.Size = Vector3.new(2,2,2)
ball.BackSurface = Enum.SurfaceType.SmoothNoOutlines
ball.TopSurface = Enum.SurfaceType.SmoothNoOutlines
ball.LeftSurface = Enum.SurfaceType.SmoothNoOutlines
ball.RightSurface = Enum.SurfaceType.SmoothNoOutlines
ball.BottomSurface = Enum.SurfaceType.SmoothNoOutlines
ball.FrontSurface = Enum.SurfaceType.SmoothNoOutlines
ball.Position = Vector3.new(0, 20, 0)
--Ball Stuff up here ^

-- Camera Stuff here v
cam.CameraSubject = ball
cam.CameraType = Enum.CameraType.Custom

--Camera Stuff here ^
-- Some where down here it stops working V :p


--BodyPosition Here
local dim = true
local pos = Instance.new("BodyVelocity", ball)
--BodyPositon here

--Main Script v
-- Fowards
local Foward = function(actionName, actionInputState, actionInputObject)
    print(actionInputState)
        if actionInputObject.UserInputType == Enum.UserInputType.Keyboard  then
    if actionInputState == Enum.UserInputState.Begin 
        and pos.Velocity.X>-maxed then
        repeat pos.Velocity = pos.Velocity - Vector3.new(2,0,0) wait(0.1) 
        until pos.Velocity.X<=-maxed
        or actionInputState == Enum.UserInputState.End
    elseif (actionInputState == Enum.UserInputState.End 
    or actionInputState == Enum.UserInputState.None )
    and pos.Velocity.X<0 then
        repeat pos.Velocity = pos.Velocity + Vector3.new(2,0,0) wait(0.1) 
        until pos.Velocity.X>=0
        or actionInputState == Enum.UserInputState.Begin 
    end
    end
     end
ContextActionService:BindAction('Move Forward', Foward ,true, Enum.KeyCode.W)
--Fowards

--Backwards
local Backwards = function(actionName, actionInputState, actionInputObject)
    print(actionInputState)
    if actionInputObject.UserInputType == Enum.UserInputType.Keyboard  then
    if actionInputState == Enum.UserInputState.Begin 
        and pos.Velocity.X<maxed then
        repeat pos.Velocity = pos.Velocity + Vector3.new(2,0,0) wait(0.1) 
        until pos.Velocity.X>=maxed
        or actionInputState == Enum.UserInputState.End
    elseif (actionInputState == Enum.UserInputState.End 
    or actionInputState == Enum.UserInputState.None ) and pos.Velocity.X>0 then
        repeat pos.Velocity = pos.Velocity - Vector3.new(2,0,0) wait(0.1) 
        until pos.Velocity.X<=0
        or actionInputState == Enum.UserInputState.Begin 
    end
    end
     end
ContextActionService:BindAction('Move Backwards', Backwards ,true, Enum.KeyCode.S)
--Backwards
--Left
local Left = function(actionName, actionInputState, actionInputObject)
    print(actionInputState)
    if actionInputObject.UserInputType == Enum.UserInputType.Keyboard  then
    if actionInputState == Enum.UserInputState.Begin 
        and pos.Velocity.Z<maxed then
        repeat pos.Velocity = pos.Velocity + Vector3.new(0,0,2) wait(0.1) 
        until pos.Velocity.Z>=maxed
        or actionInputState == Enum.UserInputState.End
    elseif (actionInputState == Enum.UserInputState.End 
    or actionInputState == Enum.UserInputState.None ) and pos.Velocity.Z>0 then
        repeat pos.Velocity = pos.Velocity - Vector3.new(0,0,2) wait(0.1) 
        until pos.Velocity.Z<=0
        or actionInputState == Enum.UserInputState.Begin 
    end
    end
     end
ContextActionService:BindAction('Move Left', Left ,true, Enum.KeyCode.A)
-- Left
--Right
local Right = function(actionName, actionInputState, actionInputObject)
        if actionInputObject.UserInputType == Enum.UserInputType.Keyboard  then
    if actionInputState == Enum.UserInputState.Begin 
        and pos.Velocity.Z>-maxed then
        repeat pos.Velocity = pos.Velocity - Vector3.new(0,0,2) wait(0.1) 
        until pos.Velocity.Z<=-maxed
        or actionInputState == Enum.UserInputState.End
    elseif (actionInputState == Enum.UserInputState.End 
    or actionInputState == Enum.UserInputState.None )
    and pos.Velocity.Z<0 then
        repeat pos.Velocity = pos.Velocity + Vector3.new(0,0,2) wait(0.1) 
        until pos.Velocity.Z>=0
        or actionInputState == Enum.UserInputState.Begin 
    end
    end
     end
ContextActionService:BindAction('Move Right', Right ,true, Enum.KeyCode.D)
--Right
--Main Script ^

--Credit to Angels_Develop for going through her own spare time to make this for people
--Bless Her
0
e.e. I bet I wont get an answer because it is too complex for yall fellas out there Angels_Develop 52 — 8y
0
It's not that complex it's just a big script which is usually not seen here... KingLoneCat 2642 — 8y
0
your not addressing my problem .. Angels_Develop 52 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

Through out the whole script where ever you look for a child of something not like player.Character but like player.Character.Humanoid use the :findFirstChild("Humanoid") or :WaitForChild("Humanoid") work either of those methods and if doesn't work by the use of :findFirstChild() then use :WaitForChild() 'cause in game you have to wait for everything to load... In the first if statement you said:

repeat wait() until player.Character and plr.Character.Humanoid

Change the one above to:

repeat wait() until player.Character and plr.Character:WaitForChild("Humanoid")

or...

repeat wait() until player.Character and plr.Character:findFirstChild("Humanoid")

I hope I helped and I hope those methods and make sure you use that :findFirstChild() and :WaitForChild() method through out the whole script when finding children.

0
No no no .. that answer sucks like. really not answering my question and trying to force me to do something that will make my scripts less effiecant Angels_Develop 52 — 8y
Ad

Answer this question