Roblox: Difference between revisions

From Virtujoy Documentation
No edit summary
No edit summary
 
Line 40: Line 40:
Players.PlayerAdded:Connect(onPlayerAdded)
Players.PlayerAdded:Connect(onPlayerAdded)
</syntaxhighlight>
</syntaxhighlight>
== Place ==
* [https://www.youtube.com/watch?v=V2iMbyidODo https://www.youtube.com/watch?v=V2iMbyidODo]

Latest revision as of 07:08, 9 February 2026

Task and heartbeat

local RunService = game:GetService("RunService")
local Character = script.Parent.Parent
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
local pet = script.Parent

local function SetPetCFrame()
	pet.PrimaryPart.CFrame = HumanoidRootPart.CFrame * CFrame.new(2, 2, -3)
end -- Hroot is player's HumanoidRootPart

RunService.Heartbeat:Connect(function()
	wait()
	SetPetCFrame()
end)

Team

local Players = game:GetService("Players")

local function onPlayerAdded(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local playerScore = Instance.new("IntValue")
	playerScore.Name = "Score"
	playerScore.Value = 0
	playerScore.Parent = leaderstats
end

Players.PlayerAdded:Connect(onPlayerAdded)

Place