0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

robloxでassistant その95

Last updated at Posted at 2024-06-01

概要

robloxでassistantやってみた。
練習問題やってみた。

練習問題

VehicleSeatを、使え。

手順

  • ServerScriptServiceに、scriptを追加。
  • スクリプトを書く。

local seat = Instance.new("VehicleSeat", workspace)
seat.Position = Vector3.new(0, 1, 0)
local Players = game:GetService("Players")
local currentPlayer = nil
local me = nil
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Custom
local s = 0
local function onOccupantChanged()
	local humanoid = seat.Occupant
	if humanoid then
		local character = humanoid.Parent
		local player = Players:GetPlayerFromCharacter(character)
		if player then
			print(player.Name .. " has sat down")
			me = game.Workspace:WaitForChild(player.Name)
			currentPlayer = player
			seat.Position += Vector3.new(0, 0, -10)
			me.HumanoidRootPart.Position += Vector3.new(0, 0, -10)
			return
		end
	end
	if currentPlayer then
		print(currentPlayer.Name .. " has got up")
		currentPlayer = nil
	end
end
seat:GetPropertyChangedSignal("Occupant"):Connect(onOccupantChanged)
seat:GetPropertyChangedSignal("Steer"):Connect(function()
	print(seat.Steer)
	if seat.Steer == 1 then
		s += -10
		camera.CFrame *= CFrame.Angles(0, math.rad(-10), 0)
		seat.CFrame *= CFrame.Angles(0, math.rad(-10), 0)
		me.HumanoidRootPart.CFrame *= CFrame.Angles(0, math.rad(-10), 0)
	elseif seat.Steer == -1 then
		s += 10
		camera.CFrame *= CFrame.Angles(0, math.rad(10), 0)
		seat.CFrame *= CFrame.Angles(0, math.rad(10), 0)
		me.HumanoidRootPart.CFrame *= CFrame.Angles(0, math.rad(10), 0)
	end
end)
seat:GetPropertyChangedSignal("Throttle"):Connect(function()
	print(seat.Throttle)
	if seat.Throttle == 1 then
		seat.Position += Vector3.new(math.sin(math.rad(s)) * -1, 0, math.cos(math.rad(s)) * -1)
		me.HumanoidRootPart.Position += Vector3.new(math.sin(math.rad(s)) * -1, 0, math.cos(math.rad(s)) * -1)
	elseif seat.Throttle == -1 then
		seat.Position += Vector3.new(math.sin(math.rad(s)) * 1, 0, math.cos(math.rad(s)) * 1)
		me.HumanoidRootPart.Position += Vector3.new(math.sin(math.rad(s)) * 1, 0, math.cos(math.rad(s)) * 1)
	end	
end)



写真

image.png

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?