Here's my module
I get a "rightFoot" "here1" and "nil" when the touch happens. The first function is called properly from another checkpoint script.
Here's the call:
local playerDataManager = require(workspace.PlayerDataManager)
local deadBoard = script.Parent
deadBoard.Touched:connect(function(hit)
print (hit)
playerDataManager.moveToLastCheckpoint(hit)
end)
And here's the module:
local PlayerDataManager = {}
local DataStoreService = game:GetService("DataStoreService")
local playersDataStore = DataStoreService:GetDataStore("PlayerData")
local sessionData = Instance.new("Model")
sessionData.Name = "SessionData"
local players = game:GetService("Players")
function PlayerDataManager:recordCheckpoint(hit,checkpointPart)
print(hit)
if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
local player = players:GetPlayerFromCharacter(hit.Parent)
local playerData = sessionData:FindFirstChild(tostring(player.userId))
--local checkpoint = checkpointData:FindFirstChild(tostring(player.userId))
if not playerData then
playerData = Instance.new("Model", sessionData)
playerData.Name = tostring(player.userId)
player.CharacterAdded:connect(function(character)
wait()
character:WaitForChild("HumanoidRootPart").CFrame = game.ServerStorage.CheckpointData[tostring(player.userId)].Value.CFrame * CFrame.Angles(0, 0, math.rad(-90)) + Vector3.new(0, 10, 0)
end)
end
local lastCheckpoint = playerData:FindFirstChild("LastCheckpoint")
if not lastCheckpoint then
lastCheckpoint = Instance.new("ObjectValue", playerData)
lastCheckpoint.Name = "LastCheckpoint"
end
lastCheckpoint.Value = checkpointPart
print(sessionData:FindFirstChild(tostring(player.userId)))
end
end
function PlayerDataManager:moveToLastCheckpoint(hit)
print("here1")
print(hit)
if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
local player = players:GetPlayerFromCharacter(hit.Parent)
print("here2")
local playerData = sessionData:FindFirstChild(tostring(player.userId))
if playerData then
print(playerData)
local lastCheckpoint = playerData:FindFirstChild("LastCheckpoint")
if lastCheckpoint then
print(lastCheckpoint)
player.character:WaitForChild("HumanoidRootPart").CFrame = lastCheckpoint.Value.CFrame * CFrame.Angles(0, 0, math.rad(-90)) + Vector3.new(0, 10, 0)
end
end
end
end
return PlayerDataManager

1 comment
Colons are used for methods in Lua. That's why.