#Help with movement logic

1 messages · Page 1 of 1 (latest)

royal pelican
#

You could try making a custom movement script for the player by changing DevComputerMovementMode and DevTouchMovementMode for mobile

vital void
#

Idk if this is the right way to do it but I was able to do it by putting a local script inside StartPlayerScripts:

local ContextActionService = game:GetService("ContextActionService")

local PlayerModule = script.Parent:WaitForChild("PlayerModule")
local ControlModule = PlayerModule:WaitForChild("ControlModule")
local Keyboard = ControlModule:WaitForChild("Keyboard")
Keyboard=require(Keyboard)
ControlModule=require(ControlModule)

local originalUpdateMovement=Keyboard.UpdateMovement
function setReversedControlsKeyboard(value)
  function Keyboard:UpdateMovement(inputState)
      originalUpdateMovement(self,inputState)
      self.moveVector*=value and -1 or 1
  end
  
  ControlModule:Disable()
  ControlModule:Enable()
end

setReversedControlsKeyboard(true)
#

hold on im gonna try to figure out if theres a better way since that only does it on keyboard

vital void
#

you're welcome, ill let you know if i figure it out.

#

found it i think

teal saffronBOT
#

studio** You are now Level 7! **studio

vital void
# dire crag Good luck 🫡
local PlayerModule = script.Parent:WaitForChild("PlayerModule")
local ControlModule = PlayerModule:WaitForChild("ControlModule")
local BaseCharacterController = ControlModule:WaitForChild("BaseCharacterController")
ControlModule=require(ControlModule)
BaseCharacterController=require(BaseCharacterController)

function setReversedControls(value)
    function BaseCharacterController:GetMoveVector(): Vector3
        return self.moveVector * (value and -1 or 1)
    end
end

setReversedControls(true)
--task.wait(1)
--setReversedControls(false)
#

that should work better

dire crag
vital void
#

it should work on mobile, or controller, or whatever, not just keyboard

dire crag
#

Tysm!

vital void
dire crag
#

Also I have a quick question

#

How do I reference the PlayerModule with a localscript inside of ReplicatedStorage?

vital void
#

like this

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local PlayerScripts = LocalPlayer:WaitForChild("PlayerScripts")
local PlayerModule = PlayerScripts:WaitForChild("PlayerModule")
dire crag
#

" 14:13:05.956 ReplicatedStorage.StatusEffects.StatusHandler:85: attempt to index nil with 'WaitForChild' - Server - StatusHandler:85"

#

Have any idea why?

#

Just saying line 85 is local PlayerScripts = LocalPlayer:WaitForChild("PlayerScripts")

vital void
#

wait can you send a screenshot of your code

dire crag
#

sure!

#

Like the whole thing or just the relevent part?

vital void
#

just the relevant i guess

dire crag
#

alright

vital void
#

where the error was

dire crag
#

the line "local PlayerScripts = LocalPlayer:WaitForChild("PlayerScripts")" outputs:

14:13:05.956 ReplicatedStorage.StatusEffects.StatusHandler:85: attempt to index nil with 'WaitForChild' - Server - StatusHandler:85

vital void
#

and which one was line 85 again

dire crag
#

local PlayerScripts = LocalPlayer:WaitForChild("PlayerScripts")

vital void
#

is it in a local script

#

or server script

dire crag
#

Its a module script, but its required by a local script

teal saffronBOT
#

studio** You are now Level 4! **studio

dire crag
#

Its also required by a server script, but I don't beleive that is relevent

vital void
#

if you require it from a server it will run the module script again i think. cause memory on the server is diff from the client

#

so that means it also tries to initialize LocalPlayer on the server

#

you should be able to fix it though

dire crag
#

Hmmmmm

#

I'm still kinda confused

dire crag
vital void
#

actually nvm is the part where its getting local player inside a function already

#

and is the function only called in the local script

dire crag
#

let me see

vital void
#

it looks like its in function module.Confusion

#

i missed that

dire crag
#

Yes I think the function is called by the server too

#

lemme send the server script

#

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CollectionService = game:GetService("CollectionService")
local StatusEffects = require(ReplicatedStorage.StatusEffects:WaitForChild("StatusHandler"))

local function onTouchedConfusionSource(player)
-- Apply confusion effect to player
StatusEffects.Confusion(player)
end

local function setupCharacter(character, player)
-- Connect Touched events to all ConfusionSource parts
for _, part in pairs(CollectionService:GetTagged("ConfusionSource")) do
part.Touched:Connect(function(hit)
if hit:IsDescendantOf(character) then
onTouchedConfusionSource(player)
end
end)
end

-- Also listen for new ConfusionSource parts that might be added later
CollectionService:GetInstanceAddedSignal("ConfusionSource"):Connect(function(part)
    part.Touched:Connect(function(hit)
        if hit:IsDescendantOf(character) then
            onTouchedConfusionSource(player)
        end
    end)
end)

end

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
setupCharacter(character, player)
end)
end)

vital void
#

ok, you cant invert the controls from the server is the problem then probably

#

unless you use like a remote event

dire crag
#

Lemme clarify something

#

The local script that requires the module is responsible for the inversion. The server script is what is responsible for infliction

vital void
#

wait was the error client or server sided

#

should have asked that

dire crag
#

I'm not sure, it just says its from the module script

vital void
#

is there a green or blue box to the left of the error in the output window

dire crag
#

green

#

so server ig

vital void
#

yes

#

that means somehow you are trying to get local player from the server

dire crag
#

I think I may know why

#

local function onTouchedConfusionSource(player)
-- Apply confusion effect to player
StatusEffects.Confusion(player)
end

#

This is a reference to the module script (local StatusEffects = require(ReplicatedStorage.StatusEffects:WaitForChild("StatusHandler"))

vital void
#

in your confusion function you have this:

local LocalPlayer = Players.LocalPlayer

LocalPlayer is not a thing on the server since you're calling StatusEffects.Confusion(player) from the server

instead you should use a remote event to fire to the client that tells the specific player to reverse their controls

#

and only the local script should run that portion of the confusion function

dire crag
#

Ah okay, so the client script should listen for the remote event instead of requiring the function?

vital void
#

yes

dire crag
#

got it

#

Alright, i'll let you know if I need any help with reworking the system

vital void
#

ok

#

good luck

dire crag
#

Alright its fully complete now, thanks alot