My objective is on a obby, you reach checkpoints, I have named the checkpoint part ‘p1’, ‘p2’…
To convert it into a number, I need to remove the ‘p’ but it’s isn’t working properly
I haven’t tried other methods to do it…
I only tried string.gsub
The part name is correctly obtained and has no problem, but when I use a gsub on it, it doesn’t give the good result : instead of ‘1’ I get ‘1 1’ or somethimes sometime else.
Here’s the code :
print(each.Name)
print(string.gsub(each.Name, 'p', ''))
PManager.GetPlayer(Player.UserId).Data.CurrentSave.checkpointsReached = tonumber(string.gsub(each.Name, 'p', ''))
The Entier script code
--// Services
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
--// Références
local CheckpointsFolder = workspace:WaitForChild("Checkpoints") -- Assure-toi que le dossier est bien dans Workspace
local GameFolder = game:GetService("ReplicatedStorage"):WaitForChild("Game", 3000)
local NetworkingFolder = GameFolder:WaitForChild("Networking", 3000)
local SGameFolder= ServerScriptService:WaitForChild('Game', 120)
local SComponentFolder = SGameFolder:WaitForChild('Components', 120)
--// Modules
local PManager = require(SComponentFolder.PlayerManager)
local Events = require(NetworkingFolder.Events)
for _, each: Part in CheckpointsFolder:GetChildren() do
if each.ClassName == 'Part' or each.ClassName == 'BasePart' then
each.Touched:Connect(function(P)
local Character = P.Parent
local Player = Players:GetPlayerFromCharacter(Character)
if not (Player == nil) then
Events.Player.CheckpointReached:Fire(Player, each.Name)
end
if string.lower(each.Name) == 'antifall' or string.lower(each.Name) == 'start' then
return
end
if PManager.GetPlayer(Player.UserId) then
if each.Name == 'Win' then
return
else
print(each.Name)
print(string.gsub(each.Name, 'p', ''))
PManager.GetPlayer(Player.UserId).Data.CurrentSave.checkpointsReached = tonumber(string.gsub(each.Name, 'p', ''))
print(PManager.GetPlayer(Player.Name).Data.CurrentSave.checkpointsReached)
end
end
end)
end
end