I want to make a simple coin system where the person gets coins and teleport away but the coin will not teleport
Here’s the code
local part = script.Parent
local addPoint = true
local function collect(otherPart)
local player = game.Players:FindFirstChild(otherPart.Parent.Name)
if player then
if addPoint then
addPoint = false
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1000
end
part.Position = Vector3.new(math.random(-1786,-1350),part.Position.Y, math.random (-300,160))
wait(1)
addPoint = true
end
end
part.Touched:Connect(collect)
that’s not really how getting the player works that works, try this:
local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
local part = script.Parent
local addPoint = false
part.Touched:Connect(function(otherPart)
local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
if player then
if not addPoint then
addPoint = true
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1000
end
part.CFrame = part.CFrame + Vector3.new(math.random(-1786,-1350),part.Position.Y, math.random (-300,160))
wait(1)
addPoint = false
end
end)