[SOLVED] HumanoidStateChanged function not doing what it was supposed to do, why?
Asked by
5 years ago Edited 5 years ago
Update: Just a quick update here, I've solved the problem myself. Thanks to those who tried to help :)
Explanation: So I tried to clone a CrackPart from ServerStorage to Player's LeftFoot when a player lands after jumping. However, the CrackPart is not cloned at where I wanted. Initially, I wanted the CrackPart to be cloned just below a player's foot but it ended up cloning above player's head just before a player lands which is not supposed to do so as it was supposed to do that after the player has landed.
I have 2 scripts, 1 LocalScript named "PlayerHumanoidStatsLocal" located in StarterPack and 1 ServerScript named "PlayerHumanoidStatsServer" located in ServerScriptService, and CrackPack is located in ServerStorage. Both scripts communicate through RemoteEvents.
There is no error shown.
Here's how the whole process looks like: https://vimeo.com/404506487
Here are my scripts:
LocalScript:
01 | local Player = game.Players.LocalPlayer |
02 | local HumanoidStateChangedEvent = game:GetService( "ReplicatedStorage" ):WaitForChild( "EventsFolder" ):WaitForChild( "HumanoidStateChangedEvent" ) |
04 | repeat wait() until Player.Character |
05 | if Player.Character then |
06 | Player.Character:WaitForChild( "Humanoid" ).WalkSpeed = 40 |
07 | Player.Character:WaitForChild( "Humanoid" ).JumpPower = 200 |
09 | Player.Character:WaitForChild( "Humanoid" ).StateChanged:Connect( function (OldState, NewState) |
10 | if NewState = = Enum.HumanoidStateType.Landed then |
11 | HumanoidStateChangedEvent:FireServer() |
ServerScript:
01 | local HumanoidStateChangedEvent = game:GetService( "ReplicatedStorage" ):WaitForChild( "EventsFolder" ):WaitForChild( "HumanoidStateChangedEvent" ) |
03 | HumanoidStateChangedEvent.OnServerEvent:Connect( function (Player) |
04 | print ( "Signal Received From PlayerHumanoidStatsLocal" ) |
05 | local CloneCrackPart = game:GetService( "ServerStorage" ):WaitForChild( "CrackPart" ):Clone() |
06 | CloneCrackPart.Parent = Player.Character.LeftFoot |
07 | CloneCrackPart.CFrame = Player.Character.LeftFoot.CFrame |
09 | CloneCrackPart:Destroy() |