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

Why my function doesn't detect current speed of humanoid that triggered proximity prompt?

Asked by 2 years ago

This is what happening: the function should detect the current walkspeed of humanoid that triggered proximity prompt, if humanoid current walkspeed at triggering the proximity prompt was 22, then the function prints "Success", else when my walkspeed is 16 the function prints "Fail", and the problem is that even when my current speed was 22 the function couldn't detect the speed correctly and prints "Fail". To change my walkspeed I use shift to sprint script. There is something wrong and I can't find the reason.

The script:

game.Workspace.Part.ProximityPrompt.Triggered:Connect(function(player)
    local humanoid = player.Character:WaitForChild("Humanoid")
    if humanoid.WalkSpeed == 22 then
        print("Success")
    else
        print("Fail")
    end
end)

Shift to sprint script: (I taked this script from youtube tutorial)

local UserInputService = game:GetService('UserInputService')
local sbar = script.Parent.SFrame.StaminaBar.Stamina
local stamina = 100
local running = false

stamina = math.clamp(stamina, 0, 100)

UserInputService.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.LeftShift then
        running = true
        char.Humanoid.WalkSpeed = 22
        while stamina > 0 and running do
            stamina = stamina - 1.5
            sbar:TweenSize(UDim2.new(stamina/100, 0, 1, 0), 'Out', 'Linear', 0)
            wait()
            if stamina == 0 then
                char.Humanoid.WalkSpeed = 16
            end
        end
    end
end)


UserInputService.InputEnded:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.LeftShift then
        running = false
        char.Humanoid.WalkSpeed = 16
        while stamina < 100 and not running do
            stamina = stamina +0.5
            sbar:TweenSize(UDim2.new(stamina/100, 0, 1, 0), 'Out', 'Linear', 0)
            wait()
            if stamina == 0 then
                char.Humanoid.WalkSpeed = 16
            end
        end
    end
end)

1 answer

Log in to vote
0
Answered by
C1RAXY 81
2 years ago
Edited 2 years ago

I know what is happening.

First of all, both scripts work just fine, the issue is the ProximityPromp it should be a LocalScript instead of a Script inside StarterCharacterScripts hope it helps!

Proof: https://streamable.com/3cx6ox

0
Thank you so much, it worked slimeking12399 6 — 2y
Ad

Answer this question