-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainScript.lua
More file actions
132 lines (110 loc) · 3.49 KB
/
MainScript.lua
File metadata and controls
132 lines (110 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local player = Players.LocalPlayer
-- GUI
local screenGui = Instance.new("ScreenGui")
screenGui.Name = "StopwatchGui"
screenGui.ResetOnSpawn = false -- ← これが超重要(リセットしても消えない)
screenGui.Parent = player:WaitForChild("PlayerGui")
-- メインフレーム
local frame = Instance.new("Frame")
frame.Size = UDim2.new(0, 320, 0, 140)
frame.Position = UDim2.new(0.5, -160, 0.5, -70)
frame.BackgroundColor3 = Color3.fromRGB(20,20,25)
frame.Active = true
frame.Draggable = true
frame.Parent = screenGui
Instance.new("UICorner", frame).CornerRadius = UDim.new(0, 20)
local stroke = Instance.new("UIStroke", frame)
stroke.Color = Color3.fromRGB(0,170,255)
stroke.Thickness = 2
local gradient = Instance.new("UIGradient", frame)
gradient.Color = ColorSequence.new{
ColorSequenceKeypoint.new(0, Color3.fromRGB(30,30,40)),
ColorSequenceKeypoint.new(1, Color3.fromRGB(15,15,20))
}
gradient.Rotation = 90
-- 時間表示
local timeLabel = Instance.new("TextLabel")
timeLabel.Size = UDim2.new(1, -20, 0.5, 0)
timeLabel.Position = UDim2.new(0, 10, 0, 10)
timeLabel.BackgroundTransparency = 1
timeLabel.TextColor3 = Color3.fromRGB(0,200,255)
timeLabel.TextScaled = true
timeLabel.Font = Enum.Font.GothamBold
timeLabel.Text = "0.000"
timeLabel.Parent = frame
-- ボタン生成関数
local function createButton(text, posX)
local button = Instance.new("TextButton")
button.Size = UDim2.new(0.48, 0, 0.35, 0)
button.Position = UDim2.new(posX, 0, 0.6, 0)
button.BackgroundColor3 = Color3.fromRGB(35,35,45)
button.TextColor3 = Color3.new(1,1,1)
button.Font = Enum.Font.GothamSemibold
button.TextScaled = true
button.Text = text
button.Parent = frame
Instance.new("UICorner", button).CornerRadius = UDim.new(0, 15)
button.MouseEnter:Connect(function()
TweenService:Create(button, TweenInfo.new(0.15), {
BackgroundColor3 = Color3.fromRGB(0,170,255)
}):Play()
end)
button.MouseLeave:Connect(function()
TweenService:Create(button, TweenInfo.new(0.15), {
BackgroundColor3 = Color3.fromRGB(35,35,45)
}):Play()
end)
return button
end
local toggleButton = createButton("Start", 0.02)
local resetButton = createButton("Reset", 0.5)
-- ストップウォッチ処理(キャラ非依存)
local running = false
local startTime = 0
local elapsed = 0
local function updateDisplay()
timeLabel.Text = string.format("%.3f", elapsed)
end
local function toggle()
running = not running
if running then
startTime = tick()
toggleButton.Text = "Stop"
stroke.Color = Color3.fromRGB(0,255,150)
else
elapsed = tick() - startTime + elapsed
updateDisplay()
toggleButton.Text = "Start"
stroke.Color = Color3.fromRGB(0,170,255)
end
end
local function reset()
running = false
startTime = 0
elapsed = 0
updateDisplay()
toggleButton.Text = "Start"
stroke.Color = Color3.fromRGB(0,170,255)
end
RunService.RenderStepped:Connect(function()
if running then
local current = tick() - startTime + elapsed
timeLabel.Text = string.format("%.3f", current)
end
end)
-- ボタン
toggleButton.MouseButton1Click:Connect(toggle)
resetButton.MouseButton1Click:Connect(reset)
-- キーボード
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.F then
toggle()
elseif input.KeyCode == Enum.KeyCode.R then
reset()
end
end)