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

[SOLVED] HumanoidStateChanged function not doing what it was supposed to do, why?

Asked by 4 years ago
Edited 4 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:

local Player = game.Players.LocalPlayer
local HumanoidStateChangedEvent = game:GetService("ReplicatedStorage"):WaitForChild("EventsFolder"):WaitForChild("HumanoidStateChangedEvent")

repeat wait() until Player.Character
if Player.Character then
    Player.Character:WaitForChild("Humanoid").WalkSpeed = 40
    Player.Character:WaitForChild("Humanoid").JumpPower = 200
end
Player.Character:WaitForChild("Humanoid").StateChanged:Connect(function(OldState, NewState)
    if NewState == Enum.HumanoidStateType.Landed then
        HumanoidStateChangedEvent:FireServer()
    end
end)

ServerScript:

local HumanoidStateChangedEvent = game:GetService("ReplicatedStorage"):WaitForChild("EventsFolder"):WaitForChild("HumanoidStateChangedEvent")

HumanoidStateChangedEvent.OnServerEvent:Connect(function(Player)
    print("Signal Received From PlayerHumanoidStatsLocal")
    local CloneCrackPart = game:GetService("ServerStorage"):WaitForChild("CrackPart"):Clone()
    CloneCrackPart.Parent = Player.Character.LeftFoot
    CloneCrackPart.CFrame = Player.Character.LeftFoot.CFrame
    wait(1)
    CloneCrackPart:Destroy()
end)
0
On line 2 in the local script and line 1 in the server script, you need the parenthesis after :WaitForChild because it is a function kingblaze_1000 359 — 4y
0
He already has it, you have to "view source" to see it. As a question to guest_2018, is the part that's being cloned anchored? NoahsRebels 99 — 4y
0
yes it is anchored @noahsrebels guest_20I8 266 — 4y
0
if the part is not anchored it will fall off the map @noahsrebels guest_20I8 266 — 4y

Answer this question