Attempt to perform arithmetic (mul) on number and string

Hello everyone, I created a script but here’s the catch, I have a problem with it, you give me this error forever when I have 100 strength and get on it Workspace.Endurance.Script:22: attempt to perform arithmetic (mul) on number and string - Server - Script:22

local playersInside = {}

script.Parent.Touched:Connect(function(hit)
    if hit.Name ~= "HumanoidRootPart" then return end

    local player = Player:GetPlayerFromCharacter(hit.Parent)
    if not player then return end

    local strength = player:FindFirstChild("Strength")
    local eMulti = player.eMulti.Value
    local class = player.leaderstats.Class.Value
    if not strength or strength.Value < 100 then return end

    table.insert(playersInside, player)
    while table.find(playersInside, player) do
        wait(2)
        if not table.find(playersInside, player) then return end
        local endurance = player:FindFirstChild("Endurance")
        if endurance then
            endurance.Value = endurance.Value + 1000 *class*eMulti 
        end
    end
end)

script.Parent.TouchEnded:Connect(function(hit)
    if hit.Name ~= "HumanoidRootPart" then return end

    local player = Player:GetPlayerFromCharacter(hit.Parent)
    if not player then return end

    local playerIndex = table.find(playersInside, player)
    if playerIndex then
        table.remove(playersInside, playerIndex)
    end
end)```
1 Like

Are you sure both of these are numbers and not strings?

2 Likes

To add, if you’re using a number in a string value then maybe use the tonumber function.

3 Likes

I used it didn’t work help solve or show me how to do it right to make it work, I don’t know how to solve

1 Like

What does the explorer look like?

1 Like

Yes, classes look like this in leaderstats

local Class = Instance.new(“String Value”, stats)
Class.Name = “Class”
Class.Value = “F-Class”

local Player = game:GetService("Players")

local playersInside = {}

script.Parent.Touched:Connect(function(hit)
    if hit.Name ~= "HumanoidRootPart" then return end

    local player = Player:GetPlayerFromCharacter(hit.Parent)
    if not player then return end

    local strength = player:FindFirstChild("Strength")
    local eMulti = player.eMulti.Value
    local class = player.leaderstats.Class.Value
    if not strength or strength.Value < 100 then return end

    table.insert(playersInside, player)
    while table.find(playersInside, player) do
        wait(2)
        if not table.find(playersInside, player) then return end
        local endurance = player:FindFirstChild("Endurance")
        if endurance then
            local endu = tonumber(endurance.Name)
            endurance.Value = endurance + 1000 *tonumber(class)*tonumber(eMulti) 
        end
    end
end)

script.Parent.TouchEnded:Connect(function(hit)
    if hit.Name ~= "HumanoidRootPart" then return end

    local player = Player:GetPlayerFromCharacter(hit.Parent)
    if not player then return end

    local playerIndex = table.find(playersInside, player)
    if playerIndex then
        table.remove(playersInside, playerIndex)
    end
end)```
Just remove the class from this line here:
 endurance.Value = endurance.Value + 1000 *class*eMulti 

So should be
 endurance.Value = endurance.Value + 1000*eMulti

You cannot convert a string into a number. The only time you can convert a string into a number is if the string only contains numbers else it’ll just return nil

m ok I get it can an example throw off my script I didn’t understand what you wrote earlier script

Wait a big question, what exactly are you trying to accomplish? You seem to be using a few strings inside a math equation? Math is numbers not words

I’m creating a part that serves as a workout zone

and I have 2 variables, 1 class is like rebirth and 2 is the player multiplier, i.e. gamepasses, etc

This tells me nothing, explain a bit more.

  1. What are you trying to do?
  2. What do you want to happen?
  3. When do you want it to happen?
  4. Things that should happen?

What is the value of endurance?
What is the value of eMulti?
What is the value of class?
What is the value of strength?

When you stand on a piece (these are my training zones type) you get a boost

You can go the other way, I already have one main script, but I need to combine this script and the other, but I don’t know how to connect without errors

Ok,

What is the value of endurance?
What is the value of eMulti?
What is the value of class?
What is the value of strength?

That is, by leaderstats, do you mean?

well, the value that is in the leaderstats

Ok ok ok, show me the leaderstats script that create all these values