My second very rookie question here, and I’ll preface by acknowledging that the answer is probably: “Go learn client vs server / local vs normal script and come back.”
I am working on a scoring system that awards points after a player jumps and lands. I’m also adding a multiplier that awards additional points after landing if the player first touched a part. I have a leaderstat called Experience that is increased by 10 for each landing, unless the player has touched a “tricktoken” which makes the landing worth 20. Again, I only want to award points after landing, but only after a jump has occurred (if you were to run off a building and land, that does not count).
So I have the leaderstat called Experience, and player values for JumpCheck and Multiplier. I’m using the humanoid.StateChanged event to check for the ‘Jumping’ and ‘Landed’ states and doing the following: After a jump, I set the ‘JumpCheck’ value from 0 to 1. After a landing I award 10 points times the JumpCheck value, and the Multiplier value. After awarding the points the JumpCheck goes back to zero and the Trick Multiplier back to 1.
01 | local character = script.Parent |
02 | local humanoid = character:WaitForChild( "Humanoid" ) |
03 | local player = game.Players:GetPlayerFromCharacter(script.Parent) |
04 | local Multiplier = player.Multiplier.Value |
05 | local JumpCheck = player.JumpCheck.Value |
07 | humanoid.StateChanged:Connect( function (oldState, newState) |
08 | if newState = = Enum.HumanoidStateType.Jumping then |
09 | print ( "Player Just Jumped - Setting JumpCheck to 1" ) |
14 | humanoid.StateChanged:Connect( function (oldState, newState) |
15 | if newState = = Enum.HumanoidStateType.Landed then |
16 | print ( "Player just landed. If JumpCheck was 1, award 10 * the point multiplier, then reset multiplier back to 1 and jumpcheck to 0" ) |
17 | player.leaderstats.Experience.Value = player.leaderstats.Experience.Value + ( 10 * JumpCheck * Multiplier) |
All of this works well to award the normal points; 10 at a time only, but I’m sure its not optimal, and the multiplier does not work, and I’m guessing these two issues are related.
Q1: This works to award 10 points with each jump in a local script in StarterCharacterScripts. If I use a regular script, the points are only awarded sporadically/infrequently. I believe this is due to the short time that the HumanoidStateType of Jumping and Landing last – perhaps not being picked up server-side. Is having these points awarded via local script in the character bad practice?
Q2: I’ve been unable to increase my point multiplier by touching the part in the game. I’ve tried a Touched event script inside the part in the Workspace, but have been unable to actually grant the multiplied points. My desired outcome is: You hit the part, set player.Multiplier.value to 2, then you jump and set player.JumpCheck.Value to 1, then you landed and awarded 10 * Mutiplier(2) * JumpCheck(1) = 20. I'm again guessing this doesn't work due to being handled on the server (part in the Workspace)?
This is inside the part:
02 | script.Parent.Touched:Connect( function (hit) |
03 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
04 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
07 | player.Multiplier.Value = 2 |
If you made it this far, apologies for the length – I’m perfectly fine with the appropriate answer: “You’re out of your depth man – go research client, server, remote events, etc...and come back.”
Cheers, Jeff