概要
・パーツに触れたら消してスコアアップ(=ピックアップ) ※インベントリではないです
・リーダーボードを表示させる
完成品はこちら
ボールをピックアップ(リーダーボードインクリメント)
ボールをピックアップ(リーダーボードインクリメント)をチェックしよう。これは、数百万種類に及ぶ、Robloxでユーザーが作成したユニークな3Dコンテンツの一つです。
やること
①リーダーボードの作成
ServerScriptServiceにスクリプト追加して書きます
game.Players.PlayerAdded:Connect(function(you)
you.CharacterAdded:Connect(function(person)
local leaderstats = Instance.new("Folder") --
leaderstats.Name = "leaderstats"
leaderstats.Parent = you
local ball = Instance.new("IntValue")
ball.Name = "ball"
ball.Parent = leaderstats
ball.Value = 0
end)
end)
ServerScriptServiceはゲーム全体を通して行う処理
leaderstats.Name = “leaderstats”と書くと、ROBLOX側でリーダーボードと自動認識する
作成したリーダーボードの変数に対して、別のインスタンスを名前と値付きでくっつける
②何らかのパーツを配置しスクリプトを追加する
local ball = script.Parent
local sw = true
ball.Touched:Connect(function(touch)
local chara = touch.Parent
local humanoid = chara:FindFirstChild("Humanoid")
if sw == true and humanoid then
sw = false
local you = game.Players:FindFirstChild(chara.Name)
local leaderboard = you:WaitForChild("leaderstats")
local ballnumber = leaderboard:WaitForChild("ball")
ballnumber.Value = ballnumber.Value + 1
ball:Destroy()
sw = true
end
end)
これでプレイヤーがボールに触れると、ボールは消えてリーダーボードのballが1増える
課題
ボールが消えるときに音が鳴るようにしたいが、できてない
参考
とても参考になりました!ありがとうございます。
コメント