While I was making an Undertale (Undyne Chase) Infinite Runner, when I tried to add another set of obstacles, so I decided to do some tinkering with the script, but that didn't work and ended up making other players die instantly before the tutorial and my character slower than a snail, what did I do wrong?
Tested: Through Studio & Roblox Player
Attempts: 17+
1st Possible Source Of Error:
(SeverScriptService - Script - Player Mannager):
local PlayerManager = {}
local PointsService = game:GetService("PointsService")
local Configurations = require(game.ReplicatedStorage.Configurations)
local function setupLeaderstats(player)
local leaderstats = Instance.new("Model", player)
leaderstats.Name = "leaderstats"
local bestScore = Instance.new("IntValue", leaderstats)
bestScore.Name = "Best Score"
local pointHighScore = 0
pcall(function()
pointHighScore = PointsService:GetGamePointBalance(player.userId)
end)
bestScore.Value = pointHighScore
end
local function updateTutorial(player, currentTile)
local tutorialToShow = Configurations.TuturialDisplayTime[currentTile]
if tutorialToShow then
game.ReplicatedStorage.Events.ShowTutorial:FireClient(player, tutorialToShow)
end
end
function PlayerManager:Run(player, slotHeight)
local manager = {}
setupLeaderstats(player)
local running = false
local score = Instance.new("IntValue", player)
score.Name = "Score"
local tutorialFinished = false
local trackManager
player.CharacterAdded:connect(function(character)
running = true
game.ReplicatedStorage.Events.EnableControls:FireClient(player, true)
-- Load in custom animations
if character.Humanoid.RigType == Enum.HumanoidRigType.R6 then
character.Animate.walk.WalkAnim.AnimationId = Configurations.WalkAnimationR6
else
-- both must be the same animation for R15 for some reason or else it won't work
character.Animate.walk.WalkAnim.AnimationId = Configurations.WalkAnimationR15
character.Animate.run.RunAnim.AnimationId = Configurations.WalkAnimationR15
end
-- Check if the track exists (from a previous run). If so clear it out. If not create a new folder for it
local trackModel = game.Workspace.PlayerTracks:FindFirstChild(player.Name)
if not trackModel then
trackModel = Instance.new("Folder", game.Workspace.PlayerTracks)
trackModel.Name = player.Name
end
-- Tutorial track
local tutorialTracker = Instance.new("IntValue", player)
tutorialTracker.Value = tutorialFinished and -1 or 1
-- Initialize a new track for the player
trackManager = require(script.Parent.TrackManager):NewTrack(Vector3.new(0,slotHeight,0), trackModel, tutorialTracker)
-- Place character at start of track and set walkspeed
wait()
character.Humanoid.WalkSpeed = Configurations.WalkSpeed
character.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(0,slotHeight + 5,0))
character.HumanoidRootPart.CFrame = CFrame.Angles(0, math.pi,0) * character.HumanoidRootPart.CFrame
character:WaitForChild("Humanoid").Died:connect(function()
running = false
trackManager:Clear()
end)
local currentTile, lastTile
local tutorialTilesDone = 0
local lastPosition = character.HumanoidRootPart.Position
local distanceRan = 0
-- Run loop
while running do
if player.Character and character:FindFirstChild("HumanoidRootPart") then
if character.HumanoidRootPart.Position.Y < slotHeight - 10 then
character.Humanoid.Health = 0
else
-- Update distance ran
local currentPosition = player.Character.HumanoidRootPart.Position
local toCurrent = player.Character.HumanoidRootPart.CFrame:vectorToObjectSpace(currentPosition - lastPosition)
distanceRan = distanceRan + math.abs(toCurrent.Z)
player.Score.Value = player.Score.Value + math.abs(toCurrent.Z)
lastPosition = currentPosition
-- Get current tile
local ray = Ray.new(character.HumanoidRootPart.Position, Vector3.new(0,-100,0))
local part, position, normal = game.Workspace:FindPartOnRay(ray, character)
if part and part:IsDescendantOf(trackModel) then
local tile = part.Parent
while tile.Parent ~= trackModel do
tile = tile.Parent
end
-- Check if current tile has been initialized
if not currentTile then
lastTile = tile
end
-- Check if the player is on a new tile. If so then update the track
currentTile = tile
if currentTile ~= lastTile then
tutorialTilesDone = tutorialTilesDone + 1
if (not tutorialFinished) and tutorialTilesDone > #Configurations.TutorialLayout then
tutorialFinished = true
end
if not tutorialFinished then
updateTutorial(player, tutorialTilesDone)
end
local turned = (currentTile.Name ~= "Straight" and currentTile.Name ~= "Obstacle")
if (not tutorialFinished) and tutorialTilesDone <= #Configurations.TutorialLayout then turned = false end
trackManager:UpdatePosition(currentTile, turned)
lastTile = currentTile
end
end
end
end
wait()
end
game.ReplicatedStorage.Events.EnableControls:FireClient(player, false)
-- Run is over, update best score
local best = player.leaderstats["Best Score"].Value
if score.Value > best then
local diff = score.Value - best
pcall(function() PointsService:AwardPoints(player.userId, diff) end)
player.leaderstats["Best Score"].Value = score.Value
end
score.Value = 0
wait(5)
player:LoadCharacter()
end)
game.ServerStorage.Events.Pickup.Event:connect(function(pickuper)
if player == pickuper then
score.Value = score.Value + Configurations.PointsPerPickup
end
end)
manager.Cleanup = function()
running = false
if trackManager then trackManager:Clear() end
if game.Workspace.PlayerTracks:FindFirstChild(player.Name) then
game.Workspace.PlayerTracks[player.Name]:Destroy()
end
end
return manager
end
return PlayerManager
2nd Possible Source Of Error:
(ServerScriptService - Script):
-- Process Tiles
local ZoneParser = require(script.ZoneParser)
local PlayerManager = require(script.PlayerManager)
ZoneParser:ParseType("Straight")
ZoneParser:ParseType("Left")
ZoneParser:ParseType("Right")
ZoneParser:ParseType("TJunction")
ZoneParser:ParseType("Obstacle")
ZoneParser:ParseType("Obstacle2")
ZoneParser:ParseType("Tutorial")
game.Workspace.DisplayElements:Destroy()
local trackSlots = {}
for i = 1, 6 do
trackSlots[i] = {player = nil, height = 50 * i}
end
local managers = {}
game.ReplicatedStorage.Events.StartRunning.OnServerEvent:connect(function(player)
local playerSlot = player:WaitForChild("slotHeight")
local manager = PlayerManager:Run(player, playerSlot.Value)
managers[player.Name] = manager
wait()
player:LoadCharacter()
end)
game.Players.PlayerAdded:connect(function(player)
local playerSlot = nil
for i = 1, 6 do
local slot = trackSlots[i]
if not slot.player then
slot.player = player
playerSlot = slot
break
end
end
local slotHeight = Instance.new("IntValue", player)
slotHeight.Name = "slotHeight"
slotHeight.Value = playerSlot.height
end)
game.Players.PlayerRemoving:connect(function(player)
if managers[player.Name] then
managers[player.Name].Cleanup()
managers[player.Name] = nil
end
end)
Here's the WIP of the game: https://www.roblox.com/games/1543745525/Undertale-Temple-Run-WIP

5 comments
Script please. :)
https://scriptinghelpers.org/help/how-post-good-questions-answers
Like that?
Mhm. ^^
No need dude, you can just revert to the original mode where the script didn't get messed up