ok so i made this code local pointPart = script.Parent
local blue = Color3.fromRGB(0, 0, 255)
local green = Color3.fromRGB(0, 255, 0)
local red = Color3.fromRGB(255, 0, 0)
local smallPoints = 10
local bigPoints = 50
local loosePoints = 100
local Players = game:GetService("Players")
local function givingPoints(player)
local currentColor = pointPart.Color
local playerStats = player:FindFirstChild("leaderstats")
if not playerStats then return end
local playerpoints = playerStats:FindFirstChild("Points")
if not playerpoints then return end
if currentColor == blue then
playerpoints.Value += smallPoints
elseif currentColor == green then
playerpoints.Value += bigPoints
else
playerpoints.Value -= loosePoints
end
pointPart.Transparency = 1
pointPart.CanCollide = false
pointPart.CanTouch = false
local particle = Instance.new("ParticleEmitter")
particle.Color = ColorSequence.new(currentColor)
print("Added particle")
local playerCharacter = player.Character
particle.Parent = playerCharacter:WaitForChild("Head")
task.wait(1)
print("Destroying")
particle:Destroy()
pointPart:Destroy()
end
local function partTouched(otherPart)
local player = Players:GetPlayerFromCharacter(otherPart.Parent)
if player then
givingPoints(player)
end
end
pointPart.Touched:Connect(partTouched)
task.spawn(function()
while true do
pointPart.Color = blue
task.wait(2)
pointPart.Color = green
task.wait(2)
pointPart.Color = red
task.wait(2)
end
end)
and it works but everytime i tuch the part to get points i get lag spikes and i have no clue why