local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local Players = game:GetService(“Players”)
local Workspace = game:GetService(“Workspace”)
local Debris = game:GetService(“Debris”)
– Assuming PointsBlock is the part to be picked up and follows the player
local pointsBlock = game.Workspace.PointsBlock
local pickupBlock = Workspace:FindFirstChild(“pickupBLock”)
local leaderStatM = require(ReplicatedStorage.LeaderstatsModule)
– Function to make the pointsBlock follow the player’s head
local function followPlayer(player)
local character = player.Character or player.CharacterAdded:Wait()
local head = character:WaitForChild(“Head”)
local connection
connection = game:GetService("RunService").Heartbeat:Connect(function()
if pointsBlock and head then
pointsBlock.Position = head.Position + Vector3.new(0, 3, 0)-- Adjust the Vector3 value as needed
if player:FindFirstChild("leaderstats") then
local leaderstats = player:FindFirstChild("leaderstats")
local points = leaderstats:FindFirstChild("Points")
if points then
points.Value = points.Value + 1
end
end
else
connection:Disconnect()
end
end)
-- Disconnect the follow function if the player dies
player.CharacterRemoving:Connect(function()
if connection then
connection:Disconnect()
pointsBlock.Position = character.Position + Vector3.new(0, 5, 0) -- Adjust the Vector3 value as needed to hover above ground
end
end)
end
– Function to handle the pickup action
local function onPickup(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
followPlayer(player)
end
end
– Connect the pickupBlock Touched event to the onPickup function
pointsBlock.Touched:Connect(onPickup)
– Handle existing players and new players joining
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
– Optional: Implement logic if you want something to happen when a player spawns or respawns
print(“Welcome!”)
end)
end)
for _, player in Players:GetPlayers() do
player.CharacterAdded:Connect(function(character)
– Optional: Implement logic if you want something to happen for already existing players
print(“Dont die!”)
end)
end
– Make sure the pointsBlock is initially positioned above the pickupBlock
if pointsBlock and pickupBlock then
pointsBlock.Position = pickupBlock.Position + Vector3.new(0, 5, 0) – Adjust the Vector3 value as needed
end
Why do my code give out points so fast, I can’t seem to slow it down.