Everything in this script works, however, I want to make it so if an attribute is set to true, it would stop the run() and stop() function. How can I achieve this? I’ve tried repeat, getpropertychangedsignual, but they just break the iskeydown function.
I’ve marked the problem below. (scroll to the right to see it)
repeat task.wait() until game:IsLoaded()
local plr = game.Players.LocalPlayer
local Character = plr.Character or plr.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local Running = Character:SetAttribute("Running", true)
local notMoving = true
local isOnGround = true
local Jumped = false
local rundb = false
local lastPosition = Character.PrimaryPart.Position
local alreadyPressed = false
local RunButton = Enum.KeyCode.W
local newSpeed = Character:GetAttribute("RunSpeed")
Character:GetAttributeChangedSignal("RunSpeed"):Connect(function()
newSpeed = Character:GetAttribute("RunSpeed")
end)
local function Run()
if isOnGround == true then
Humanoid.WalkSpeed = newSpeed
end
end
local function Stop()
Humanoid.WalkSpeed = Character:GetAttribute("WalkSpeed")
end
UIS.InputBegan:Connect(function(input, isTyping)
if isTyping then return end
if UIS:IsKeyDown(RunButton) and Character:GetAttribute("Stunned") == false and Character:GetAttribute("Blocking") == false and alreadyPressed == false then --the problem
Run()
alreadyPressed = true
end
end)
UIS.InputEnded:Connect(function(input, isTyping)
if isTyping then return end
if not UIS:IsKeyDown(RunButton) and Character:GetAttribute("Stunned") == false and Character:GetAttribute("Blocking") == false and alreadyPressed == true then --the problem
Stop()
alreadyPressed = false
end
end)