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?

robloxでassistant その209

Posted at

概要

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

練習問題

プラグインで、コイン収集システムをデプロイせよ。

写真

image.png

サンプルコード



local tb = plugin:CreateToolbar("test5")
local button = tb:CreateButton("test desu", "run", "http://www.roblox.com/asset/?id=10164183611")
button.ClickableWhenViewportHidden = true
local widgetInfo = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, false, true, 300, 200)
local dragSourceWidget = plugin:CreateDockWidgetPluginGui("Customization", widgetInfo)
local testButton1 = Instance.new("TextButton")
local testButton2 = Instance.new("TextButton")
local testButton3 = Instance.new("TextButton")

testButton1.BorderSizePixel = 0
testButton1.TextSize = 20
testButton1.TextColor3 = Color3.new(0.32549, 0.32549, 0.32549)
testButton1.AnchorPoint = Vector2.new(0.5, 0.5)
testButton1.Size = UDim2.new(1, 0, 0.1, 0)
testButton1.Position = UDim2.new(0.5, 0, 0.1, 0)
testButton1.SizeConstraint = Enum.SizeConstraint.RelativeYY
testButton1.Text = "remote"
testButton1.Parent = dragSourceWidget

testButton2.BorderSizePixel = 0
testButton2.TextSize = 20
testButton2.TextColor3 = Color3.new(0.32549, 0.32549, 0.32549)
testButton2.AnchorPoint = Vector2.new(0.5, 0.5)
testButton2.Size = UDim2.new(1, 0, 0.1, 0)
testButton2.Position = UDim2.new(0.5, 0, 0.3, 0)
testButton2.SizeConstraint = Enum.SizeConstraint.RelativeYY
testButton2.Text = "coin"
testButton2.Parent = dragSourceWidget

testButton3.BorderSizePixel = 0
testButton3.TextSize = 20
testButton3.TextColor3 = Color3.new(0.32549, 0.32549, 0.32549)
testButton3.AnchorPoint = Vector2.new(0.5, 0.5)
testButton3.Size = UDim2.new(1, 0, 0.1, 0)
testButton3.Position = UDim2.new(0.5, 0, 0.5, 0)
testButton3.SizeConstraint = Enum.SizeConstraint.RelativeYY
testButton3.Text = "button3"
testButton3.Parent = dragSourceWidget

testButton1.MouseButton1Down:Connect(function()
	if game:GetService("ReplicatedFirst"):FindFirstChild("helloscript") then
		game.ReplicatedFirst.helloscript:Destroy();
	end
	local helloScript = Instance.new("LocalScript")
	helloScript.Name = "helloscript"
	helloScript.Parent = game.ReplicatedFirst
	helloScript.Source = [[
local workspace = game.Workspace
local part = Instance.new("Part", workspace)
part.Position = Vector3.new(0, 1, -9)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remote = ReplicatedStorage:WaitForChild("RemoteEvent")
local clickDetector = Instance.new("ClickDetector")
clickDetector.Parent = part  
clickDetector.MouseClick:Connect(function(player)
	print("clicked")
	if Remote then
		print("fire")
		Remote:FireServer()
	end
end)
	]]
	if game:GetService("ServerScriptService"):FindFirstChild("ohiscript") then
		game.ServerScriptService.ohiscript:Destroy();
	end
	local helloScript = Instance.new("Script")
	helloScript.Name = "ohiscript"
	helloScript.Parent = game.ServerScriptService
	helloScript.Source = [[
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remote = Instance.new("RemoteEvent", ReplicatedStorage)
Remote.OnServerEvent:Connect(function(player)
	print("fire server ok")
	print(player.Name)
	local fire = Instance.new("Fire")
	fire.Heat = 10
	fire.Color = Color3.new(1, 0, 0)
	fire.SecondaryColor = Color3.new(1, 1, 1)
	fire.Size = math.max(10, 10)
	fire.Parent = workspace
end)
	]]
	print("ok1")
end)

testButton2.MouseButton1Down:Connect(function()
	if game:GetService("ServerScriptService"):FindFirstChild("ohiscript") then
		game.ServerScriptService.ohiscript:Destroy();
	end
	local helloScript = Instance.new("Script")
	helloScript.Name = "ohiscript"
	helloScript.Parent = game.ServerScriptService
	helloScript.Source = [[
local DataStoreService = game:GetService("DataStoreService")
local playerData = DataStoreService:GetDataStore("PlayerData0")

local function saveData(key, val)
	local success, errorMessage = pcall(function()
		playerData:SetAsync(key, val)
	end)
	if success then
		print("Data saved successfully!")
	else
		warn("Cannot save data for player!")
	end
end

local function loadData(key)
	local val
	local success, errorMessage = pcall(function()
		val = playerData:GetAsync(key)
	end)
	return val
end

game.Players.PlayerAdded:Connect(function(player)
	print("入った")
	local v = loadData(player.UserId .. "-coin")
	if v == nil then
		v = 0
	end
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	local coin = Instance.new("IntValue", leaderstats)
	coin.Name = "coin"
	coin.Value = v
end)

game.Players.PlayerRemoving:Connect(function(player)
	print("出た")
	local v = player.leaderstats.coin.Value
	saveData(player.UserId .. "-coin", v)
end)

local Players = game:GetService("Players")

local bomb = Instance.new("Part", workspace)
bomb.Name = "bomb"
bomb.Anchored = false
bomb.Shape = Enum.PartType.Cylinder
bomb.BrickColor = BrickColor.Red()
bomb.Size = Vector3.new(0.5, 3, 3)
local explosionSound = Instance.new("Sound")
explosionSound.SoundId = "rbxassetid://5137964328"
explosionSound.Parent = bomb
local function explode()
	local explosion = Instance.new("Explosion")
	explosion.BlastRadius = 10
	explosion.BlastPressure = 500000
	explosion.Position = bomb.Position
	explosion.Parent = game.Workspace
	explosionSound:Play()
end
bomb.Touched:Connect(function(hit)
	local character = hit.Parent
	local humanoid = character:FindFirstChildWhichIsA("Humanoid")
	if humanoid then
		local player = Players:GetPlayerFromCharacter(character)
		bomb:Destroy()
		player.leaderstats.coin.Value = 0
		explode()
	end
end)
local x = math.random(-20, 20)
local z = math.random(-20, 20)
bomb.Position = Vector3.new(x, 8, z)
while true do
	local part = Instance.new("Part", workspace)
	part.Name = "Coin"
	part.Anchored = false
	part.Shape = Enum.PartType.Cylinder
	part.BrickColor = BrickColor.Yellow()
	part.Size = Vector3.new(0.5, 3, 3)
	part.Touched:Connect(function(hit)
		local character = hit.Parent
		local humanoid = character:FindFirstChildWhichIsA("Humanoid")
		if humanoid then
			local player = Players:GetPlayerFromCharacter(character)
			part:Destroy()
			player.leaderstats.coin.Value += 1
		end
	end)
	local x = math.random(-30, 30)
	local z = math.random(-30, 30)
	part.Position = Vector3.new(x, 8, z)
	wait(2)
end
	]]
	print("ok2")

end)

testButton3.MouseButton1Down:Connect(function()
	print("ok3")
end)

button.Click:Connect(function()
	dragSourceWidget.Enabled = true
end)




以上。

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?