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 comment
Thank you so much, it worked