-- サンプルScriptセット --------------------------------------------------------------- -- ▼ 表示する・隠す --------------------------------------------------------------- -- 透明度を変える script.Parent.Transparency = 0 -- 表示する script.Parent.Transparency = 0.5 -- 半透明にする script.Parent.Transparency = 1 -- 隠す -- ぶつかる判定 script.Parent.CanCollide = true -- ぶつかる script.Parent.CanCollide = false -- すり抜ける -- 「触れたら」のコードに反応するかどうか script.Parent.CanTouch = true -- 触れたら反応する script.Parent.CanTouch = false -- 触れても無反応にする -- ずっと 5秒ごとに表示→透明を繰り返す while true do script.Parent.Transparency = 0 task.wait(5) script.Parent.Transparency = 1 task.wait(5) end -- キャラクターが親ブロックに触れたら 1秒後に透明になってCanCollideオフ、5秒後に再表示 local block = script.Parent block.Touched:Connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid then task.wait(1) block.Transparency = 1 block.CanCollide = false task.wait(5) block.Transparency = 0 block.CanCollide = true end end) -- 親ブロックに触れたら Workspaceにある「消すブロック」を隠して触れられないようにする script.Parent.Touched:Connect(function(hit) local player = hit.Parent if game.Players:GetPlayerFromCharacter(player) then workspace["消すブロック"].Transparency = 1 workspace["消すブロック"].CanCollide = false end end) --------------------------------------------------------------- -- ▼ 色・素材を変える --------------------------------------------------------------- -- 赤 script.Parent.Color = Color3.fromRGB(255, 0, 0) -- 青 script.Parent.Color = Color3.fromRGB(0, 0, 255) -- 黄 script.Parent.Color = Color3.fromRGB(255, 255, 0) -- ランダムカラー script.Parent.Color = Color3.new(math.random(), math.random(), math.random()) -- 素材をネオンに変更 script.Parent.Material = Enum.Material.Neon -- ずっと 1秒ごとにランダムな色になる while true do script.Parent.Color = Color3.new(math.random(), math.random(), math.random()) task.wait(1) end -- ▼ キャラクターが親ブロックに触れたら 色を緑に変える script.Parent.Touched:Connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid then script.Parent.Color = Color3.fromRGB(0, 255, 0) end end) --------------------------------------------------------------- -- ▼ 位置・回転・固定 --------------------------------------------------------------- -- (X,Y,Z) の位置に置く script.Parent.Position = Vector3.new(0,15,0) -- 今いる位置から(X,Y,Z)動かす script.Parent.Position += Vector3.new(0, 20, 0) -- (X,Y,Z)の方向に向ける script.Parent.Orientation += Vector3.new(0, 90, 0) -- 今の方向から(X,Y,Z)の方向に回転 script.Parent.Orientation += Vector3.new(0, 90, 0) -- 固定をオンにする(動かしたくない・落下させたくない) script.Parent.Anchored = true -- 固定をオフにする(動かしたい・落下させたい) script.Parent.Anchored = false -- ずっと 少しずつ上に動き続ける(前に進める場合プレイヤーはついていかない) while true do script.Parent.Position += Vector3.new(0, 0.1, 0) -- 少し動く task.wait(0.02) end -- ずっと 回し続ける(プレイヤーは乗っても一緒に回らない) while true do script.Parent.Orientation += Vector3.new(0, 2, 0) task.wait(0.02) end -- キャラクターが親ブロックに触れたら 固定をオフにして動かせるようにする script.Parent.Touched:Connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid then script.Parent.Anchored = false end end) -- キャラクターが親ブロックに触れたら 少しだけ上がって、すぐ下がる local flag = false script.Parent.Touched:Connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid then -- もしフラグ(flag)がオフなら実行する ※フラグにしないと連続で動いてしまうため if flag == false then flag = true -- すぐフラグオンにする script.Parent.Position += Vector3.new(0, 1, 0) task.wait(0.15) script.Parent.Position -= Vector3.new(0, 1, 0) task.wait(1) -- フラグオンのまま1秒待つ flag = false -- フラグオフにして再実行できるようにする end end end) -- 親ブロックに触れたら ワープ先のY座標+5の位置に移動する -- ※必ず「 ワープ先 」という名前のブロックが必要です 他の名前にしたいならアレンジしましょう script.Parent.Touched:Connect(function(hit) local player = hit.Parent if game.Players:GetPlayerFromCharacter(player) then player:SetPrimaryPartCFrame( workspace["ワープ先"].CFrame + Vector3.new(0, 5, 0) ) end end) --------------------------------------------------------------- -- ▼ 大きさ --------------------------------------------------------------- -- Xを3 Yを5 Xを10 の大きさ(サイズ)にする script.Parent.Size = Vector3.new(3, 5, 10) -- XYZを1ずつ大きくする script.Parent.Size += Vector3.new(1, 1, 1) -- XYZを0.5ずつ小さくする script.Parent.Size -= Vector3.new(0.5, 0.5, 0.5) -- XYZをランダムな大きさにする script.Parent.Size = Vector3.new( math.random(1, 10), math.random(1, 10), math.random(1, 10) ) -- キャラクターが触れたらXYZが2ずつ大きくなる local flag = false script.Parent.Touched:Connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid then -- もしフラグがオフなら実行する ※フラグにしないと連続で動いてしまうため if flag == false then flag = true -- すぐフラグオンにする script.Parent.Size += Vector3.new(2, 2, 2) task.wait(1) -- フラグオンのまま1秒待つ flag = false -- フラグオフにして再実行できるようにする end end end) -- ずっと少しずつ大きくなる while true do -- 10回大きくなる for i = 1, 10 do script.Parent.Size += Vector3.new(0.1, 0.1, 0.1) task.wait(0.02) end -- 10回小さくなる for i = 1, 10 do script.Parent.Size -= Vector3.new(0.1, 0.1, 0.1) task.wait(0.02) end end --------------------------------------------------------------- -- ▼ 体力・ダメージ --------------------------------------------------------------- -- キャラクターが親ブロックに触れたら 10ダメージ与える local flag = false script.Parent.Touched:Connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid then -- もしフラグがオフなら実行する ※フラグにしないと連続で動いてしまうため if flag == false then flag = true -- すぐフラグオンにする humanoid:TakeDamage(10) task.wait(1) -- フラグオンのまま1秒待つ flag = false -- フラグオフにして再実行できるようにする end end end) -- キャラクターが親ブロックに触れたら HPを100(全回復)にする script.Parent.Touched:Connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid then humanoid.Health = 100 end end) --------------------------------------------------------------- -- ▼ 音 --------------------------------------------------------------- -- キャラクターが親ブロックに触れたら 音を鳴らす -- ※親ブロックの中(このScriptと同じ位置)にSoundという名前の音素材が必要です script.Parent.Touched:Connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid then script.Parent.Sound:Play() end end) --------------------------------------------------------------- -- ▼ 環境 --------------------------------------------------------------- -- 20時にする game.Lighting.ClockTime = 20 -- 触れたら夜(20時)になる script.Parent.Touched:Connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid then game.Lighting.ClockTime = 20 end end) -- ゲーム世界の重力を普通にする workspace.Gravity = 196.2 -- ゲーム世界の重力を約1/10にして全員をふわふわジャンプにする workspace.Gravity = 20 --------------------------------------------------------------- -- ▼ もっと極めたい人向けの基本文法 --------------------------------------------------------------- -- print()の使い方 print(1) -- 数値1を表示する print("こんにちは!") -- こんにちは!を表示する print(script.Parent.Transparency) -- 親ブロックの透明度を表示する print("透明度は "..script.Parent.Transparency) -- 文字と透明度をつなげて表示する -- 変数の基本 local time = 3 -- 変数timeを作り 3を入れておく task.wait(time) -- 3秒待つ print(time.."秒待ちました") -- つなげて「3秒待ちました」と表示する ( )と( )ブロックのコード版 time = 5 -- 変数を後から上書きする time += 1 -- 変数に+1する time -= 1 -- 変数に-1する -- script.Parentを変数に入れて コードを省略できる -- 元のコード script.Parent.Transparency = 0.8 print(script.Parent.Transparency) print(script.Parent.CanCollide) -- ↓ 変数化したコード local b = script.Parent b.Transparency = 0.8 print(b.Transparency) print(b.CanCollide) -- もし~ならば の基本 local time = 15 if time > 10 then print("時間が10より大きいです") end -- ずっと もし親ブロックのY座標が10より小さいなら (0,100,0)の位置に移動する while true do if script.Parent.Position.Y < 10 then script.Parent.Position = Vector3.new(0,100,0) end task.wait(0.1) -- ループは少し待たないと動きすぎてクラッシュする end -- 10回繰り返す for i = 1, 10 do task.wait(0.03) -- ループは 待つ とセットで使う end -- 100回繰り返す for i = 1, 100 do task.wait(0.03) -- ループは 待つ とセットで使う end