can someone please help me with this scirpt! its supposed to change players jumppower to 150 after a remote event is fired but it doesnt change the jumpower can someone please fix it! i really dont see wehre tis wrong
local Players = game:GetService("Players")
-- Reference to the RemoteEvent
local jumpPowerEvent = script.Parent.RemoteEvent
-- Function to change jump power
local function onJumpPowerEvent()
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
-- Store the original JumpPower
local originalJumpPower = humanoid.JumpPower
-- Modify Humanoid's JumpPower property directly
humanoid.JumpPower = 150
-- Wait for 1 second and then reset JumpPower
wait(1)
humanoid.JumpPower = originalJumpPower
end
-- Connect the function to the RemoteEvent
jumpPowerEvent.OnClientEvent:Connect(onJumpPowerEvent)
-- local script events function as:
local Event = Path.To.Event
Event.OnClientEvent(any)
-- server script events function as:
local Event = Path.To.Event
local TargetPlayer = player
Event:FireClient(TargetPlayer, any)
or
Event:FireAllClients(any)
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local originalJumpPower = humanoid.JumpPower
-- Reference to the RemoteEvent
local jumpPowerEvent = script.Parent.RemoteEvent
-- Function to change jump power
local function onJumpPowerEvent()
-- Modify Humanoid's JumpPower property directly
humanoid.JumpPower = 150
-- Wait for 1 second and then reset JumpPower
wait(1)
humanoid.JumpPower = originalJumpPower
end
-- Connect the function to the RemoteEvent
jumpPowerEvent.OnClientEvent:Connect(onJumpPowerEvent)
everytime you call the function you are setting the variable again and again @super_marvel1232
Hiyah, I took a reading of what happened here.
My questions are.
1: Is this script a server script or localscript?
2: Is the remote being fired from a server script?
Buddy why are you changing it on the client, you can (read: NEED to)change it on the server itself. Also you need to tell the script you want to use the jump power before changing it
Final code in A SERVER SCRIPT
—[[I’m going to change the power
When the player joins, you change that
to whatever event you use to change the power]]—
game.Players.PlayerAdded:Connect(function(plr)
local hum = (plr.Character or plr.CharacterAdded:Wait()).Humanoid
local originalpower = hum.JumpPower
hum.UseJumpPower = true
hum.JumpPower = 150
wait(1)
hum.JumpPower = originalpower
end)
The problem in your script is probably because you are trying to change the JumpPower property of the humanoid on the client side (i.e. on the local player). Changes to the physical properties of player elements (like JumpPower) on the client side are often not replicated and can therefore be ignored by the server.