So I made a part in my game where when touched, it would convert the points you collected into XP and coins, however, a script error with no relevance to the script appears. Here's the code:
local part = script.Parent
local canGet = true
local DataStore2 = require(1936396537)
local function onTouch(otherPart)
local humanoid = otherPart.Parent:FindFirstChild('Humanoid')
if humanoid then
local player = game.Players:FindFirstChild(otherPart.Parent.Name)
if player and canGet then
canGet = false
local r1 = player.PlayerPoints
local r2 = player.PlayerPointsR2
local r3 = player.PlayerPointsR3
local XPStore = DataStore2("XP",player)
local CoinsStore = DataStore2("Coins",player)
local total = r1.Value + r2.Value + r3.Value
XPStore:Increment(total)
CoinsStore:Increment(total / 2)
r1.Value = r1.Value - r1.Value
r2.Value = r2.Value - r2.Value
r3.Value = r3.Value - r3.Value
local teleportpart = script.Parent
teleportpart.Touched:Connect(function(hit)
game.Players[tostring(hit.Parent.Name)].Character:SetPrimaryPartCFrame(CFrame.new(24.41, 10.195, 63.026)) --this is where the problem is.
end)
end
wait(0.25)
canGet = true
end
end
part.Touched:Connect(onTouch)
(The script error is: ClassicSword is not a valid member of Players (line 24).)
Any help will be appreciated!
