#Help with movement logic
1 messages · Page 1 of 1 (latest)
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
Awesome, thank you very much
Good luck 🫡
** You are now Level 7! **
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
May I ask what's the difference with this one?
it should work on mobile, or controller, or whatever, not just keyboard
Tysm!
np
Also I have a quick question
How do I reference the PlayerModule with a localscript inside of ReplicatedStorage?
like this
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local PlayerScripts = LocalPlayer:WaitForChild("PlayerScripts")
local PlayerModule = PlayerScripts:WaitForChild("PlayerModule")
" 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")
wait can you send a screenshot of your code
just the relevant i guess
alright
where the error was
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
and which one was line 85 again
local PlayerScripts = LocalPlayer:WaitForChild("PlayerScripts")
Its a module script, but its required by a local script
** You are now Level 4! **
Its also required by a server script, but I don't beleive that is relevent
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
In what sense?
actually nvm is the part where its getting local player inside a function already
and is the function only called in the local script
let me see
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)
ok, you cant invert the controls from the server is the problem then probably
unless you use like a remote event
Lemme clarify something
The local script that requires the module is responsible for the inversion. The server script is what is responsible for infliction
I'm not sure, it just says its from the module script
is there a green or blue box to the left of the error in the output window
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"))
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
Ah okay, so the client script should listen for the remote event instead of requiring the function?
yes
Alright its fully complete now, thanks alot