#It's value stacks when it should not

1 messages · Page 1 of 1 (latest)

half linden
#

Can you help me fix my script:

local Workspace = game:GetService("Workspace")
local remoteEvent = game.ReplicatedStorage:FindFirstChild("ThreadmillRemoteEvent")
local RemoteEvent = game.ReplicatedStorage:FindFirstChild("AddXPFromThreadmillRemoteEvent")
local player = game.Players.LocalPlayer
local character = game.Workspace:FindFirstChild(player.Name)
local isLoopRunning = false
local doItAnyway = false

local function Raycast(player)
    if isLoopRunning or doItAnyway then return end
    isLoopRunning = true
    
    while isLoopRunning or doItAnyway do
        local leftFoot = player.Character.LeftFoot
        local rayOrigin = leftFoot.Position
        local rayDirection = Vector3.new(0, -5, 0)

        local raycastResult = Workspace:Raycast(rayOrigin, rayDirection)

        if raycastResult.Instance.Name == "RunningPart" then
            RemoteEvent:FireServer()
            doItAnyway = true
            isLoopRunning = true
        else
            doItAnyway = false
            isLoopRunning = false
        end
        task.wait(0.6)
    end
    
    doItAnyway = false
    isLoopRunning = false
end

remoteEvent.OnClientEvent:Connect(function(boolValue)
    if boolValue then
        Raycast(player)
    end
end)

It starts giving 20 when you go off and go on fast. It should give 10 only

dapper marten