Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Made by KrYn0MoRe
- --DevSersponge helped w/ effects :>
- local partfolder = Instance.new("Folder")
- partfolder.Parent = script
- local clickX,clickO
- --[[
- 1,2,3
- 4,5,6
- 7,8,9
- ]]
- local ways = {
- {n1 = 1,n2 = 2,n3 = 3},
- {n1 = 4,n2 = 5,n3 = 6},
- {n1 = 7,n2 = 8,n3 = 9},
- {n1 = 1,n2 = 5,n3 = 9},
- {n1 = 3,n2 = 5,n3 = 7},
- {n1 = 1,n2 = 4,n3 = 7},
- {n1 = 2,n2 = 5,n3 = 8},
- {n1 = 3,n2 = 6,n3 = 9},
- }
- local plots = {}
- local parts = {}
- local win_songs = {
- {453967617,1,0},
- {1843322216,1,0},
- {2969532905,1,0},
- {341673299,1,25},
- {682070138,1,0},
- {2586407163,0.8,10},
- }
- local total = 0
- local playing = false
- local O,X,turn
- local multiplier = 3
- local s = 3
- local start_time = 5
- local turn_time = 10
- local win_time = 10
- local line_size = 0.05
- local tid = 0
- local maintext,board,stand
- local curline=nil
- local firstpart=nil
- local lastpart=nil
- local currentwinner=0
- function check()
- local winner = nil
- for i,way in pairs(ways) do
- if winner~=nil then break end
- pcall(function()
- local v1,v2,v3 = plots[way.n1], plots[way.n2], plots[way.n3]
- firstpart=v1
- lastpart=v3
- if (v1 and v2 and v3) then
- if (v1['plrval'].Value == X and v2['plrval'].Value == X and v3['plrval'].Value == X) then
- winner = X
- currentwinner=0
- elseif (v1['plrval'].Value == O and v2['plrval'].Value == O and v3['plrval'].Value == O) then
- winner = O
- currentwinner=1
- end
- end
- end)
- end
- if winner~=nil then
- local distance = (firstpart.CFrame.p+Vector3.new(0,.5,0)-lastpart.CFrame.p+Vector3.new(0,.5,0)).magnitude
- curline=Instance.new("Part",firstpart.Parent)
- curline.Anchored=true
- if currentwinner==0 then
- curline.Color=Color3.new(1,0,0)
- else
- curline.Color=Color3.new(0,0,1)
- end
- curline.Material="Neon"
- curline.Size=Vector3.new(.1,.5,.5)
- curline.CFrame=CFrame.new(lastpart.CFrame.p+Vector3.new(0,.5,0),firstpart.CFrame.p+Vector3.new(0,.5,0))*CFrame.Angles(0,math.rad(90),0)
- --sine
- spawn(function()
- for i=1,#parts do
- if parts[i]==nil then return end
- if parts[i]:IsA("BasePart") then
- spawn(function()
- local currentpart=parts[i]
- local pos=currentpart.Position
- for z=1,100 do
- local delta=z/100
- pcall(function()
- currentpart.Position=pos+Vector3.new(0,1*math.sin(z*0.25),0)
- wait()
- end)
- end
- for z=1,20 do
- local delta=z/20
- pcall(function()
- currentpart.Position=p.Position:lerp(pos,delta)
- wait()
- end)
- end
- currentpart.Position=pos
- coroutine.yield()
- end)
- end
- wait(.1)
- end
- coroutine.yield()
- end)
- --sine
- spawn(function()
- for i=1,150 do
- pcall(function()
- local delta=i/110
- curline.Size = curline.Size:lerp(Vector3.new(distance+2,.5,.5),delta) --/ 2
- curline.CFrame = curline.CFrame:lerp(CFrame.new(firstpart.CFrame.p+Vector3.new(0,.5,0),lastpart.CFrame.p+Vector3.new(0,.5,0)) *CFrame.new(0, 0, -distance/2)*CFrame.Angles(math.rad(0),math.rad(90),math.rad(0)),delta)
- wait()
- end)
- end
- coroutine.yield()
- end)
- end
- return winner
- end
- function set_turn(plr)
- local cid = tid
- local name = plr.Name
- turn = plr
- spawn(function()
- local _time = turn_time
- repeat
- _time -= 1;
- wait(1);
- if playing then
- update(name .. "'s Turn. (" .. _time .. ')')
- end
- until 0 >= _time or tid ~= cid or not playing or not X or not O
- if X and not O then
- get_result(X)
- return
- elseif O and not X then
- get_result(O)
- return
- end
- if not playing then
- return
- end
- if tid == cid then
- if turn == X then
- set_turn(O)
- else
- set_turn(X)
- end
- end
- end)
- end
- function make(p1,p2,p3)
- board = Instance.new("Model")
- board.Parent = partfolder
- parts = {}
- for column = 1,multiplier do
- for row = 1,multiplier do
- local part = Instance.new("Part")
- part.Color = Color3.new(1,1,1)
- part.Anchored = true
- part.CanCollide = true
- part.Locked = true
- part.Material = Enum.Material.SmoothPlastic
- part.Size = Vector3.new(s,1,s)
- part.CFrame = CFrame.new(p1+((s+line_size*2)*row),p2,p3+((s+line_size*2)*column))*CFrame.Angles(0,math.rad(90),0)
- part.Name = tostring(((column-1)*multiplier)+row)
- part.Parent = board
- table.insert(parts,part)
- local grid = Instance.new("SelectionBox")
- grid.LineThickness = line_size
- grid.Color3 = Color3.new(0,0,0)
- grid.Adornee = part
- grid.Parent = part
- local plrval = Instance.new("ObjectValue",part)
- plrval.Name = "plrval"
- local SurfaceGui0 = Instance.new("SurfaceGui")
- local TextBox1 = Instance.new("TextBox")
- SurfaceGui0.Parent = part
- SurfaceGui0.LightInfluence = 1
- SurfaceGui0.Face = Enum.NormalId.Top
- SurfaceGui0.PixelsPerStud = 50
- SurfaceGui0.SizingMode = Enum.SurfaceGuiSizingMode.PixelsPerStud
- SurfaceGui0.ClipsDescendants = true
- SurfaceGui0.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
- TextBox1.Parent = SurfaceGui0
- TextBox1.Size = UDim2.new(1, 0, 1, 0)
- TextBox1.BackgroundTransparency = 1
- TextBox1.Text = ""
- TextBox1.TextScaled = true
- local clicker = Instance.new("ClickDetector")
- clicker.MaxActivationDistance = 15
- clicker.Parent = part
- local clicked = false
- clicker.MouseClick:Connect(function(plr)
- if plr and turn == plr and not clicked and playing then
- clicked = true
- tid += 1
- local s = Instance.new("Sound")
- s.SoundId = 'rbxassetid://452267918'
- s.Volume = 1
- s.Parent = part
- s:Play()
- if plr == X and turn == X then
- clicker:Destroy()
- TextBox1.Text = "X"
- plrval.Value = X
- set_turn(O)
- game:GetService("TweenService"):Create(grid,TweenInfo.new(1),{Color3 = Color3.new(1,0,0)}):Play()
- elseif plr == O and turn == O then
- clicker:Destroy()
- TextBox1.Text = "O"
- plrval.Value = O
- set_turn(X)
- game:GetService("TweenService"):Create(grid,TweenInfo.new(1),{Color3 = Color3.new(0,0,1)}):Play()
- end
- total += 1
- plots[tonumber(part.Name)] = part
- local winner = check()
- get_result(winner)
- end
- end)
- end
- end
- end
- function get_result(winner)
- if winner then
- playing = false
- local song = win_songs[math.random(1,#win_songs)]
- local win_s = Instance.new("Sound")
- win_s.SoundId = 'rbxassetid://' .. song[1]
- win_s.PlaybackSpeed = song[2]
- win_s.TimePosition = song[3]
- win_s.Volume = 3
- win_s.Parent = stand.PrimaryPart
- win_s:Resume()
- for i = 1,win_time-1 do
- update(winner.Name .. " Won! (" .. tostring(win_time-i) .. ')')
- wait(1)
- end
- win_s:Destroy()
- start()
- elseif total >= multiplier^2 then
- playing = false
- spawn(function()
- for i=1,#parts do
- local currentpart=parts[i]
- spawn(function()
- local pos=currentpart.Position
- for z=1,100 do
- local delta=z/100
- pcall(function()
- currentpart.Size=currentpart.Size:lerp(Vector3.new(.1,.1,.1),delta)
- currentpart.Rotation=currentpart.Rotation:lerp(Vector3.new(0,math.rad(90),math.rad(180)),delta)
- wait()
- end)
- end
- end)
- end
- end)
- for i = 1,win_time-1 do
- update("Draw. (" .. tostring(win_time-i) .. ')')
- wait(1)
- end
- start()
- end
- end
- function prepare()
- stand = Instance.new("Model")
- local Part1 = Instance.new("Part")
- local Part2 = Instance.new("Part")
- local SurfaceGui3 = Instance.new("SurfaceGui")
- local TextBox4 = Instance.new("TextBox")
- local Part5 = Instance.new("Part")
- local SurfaceGui6 = Instance.new("SurfaceGui")
- local TextBox7 = Instance.new("TextBox")
- local Part8 = Instance.new("Part")
- local SurfaceGui9 = Instance.new("SurfaceGui")
- maintext = Instance.new("TextBox")
- stand.Name = "choose"
- stand.PrimaryPart = Part1
- stand.Parent = partfolder
- Part1.Parent = stand
- Part1.CFrame = CFrame.new(-30.9599934, 4.33500385, 89.4899979, 1, 0, 0, 0, 1, 0, 0, 0, 1)
- Part1.Position = Vector3.new(-30.9599934, 4.33500385, 89.4899979)
- Part1.Color = Color3.new(0.0156863, 0.686275, 0.92549)
- Part1.Size = Vector3.new(17.0199986, 8.61000061, 2)
- Part1.Anchored = true
- Part1.BottomSurface = Enum.SurfaceType.Smooth
- Part1.BrickColor = BrickColor.new("Cyan")
- Part1.Locked = true
- Part1.TopSurface = Enum.SurfaceType.Smooth
- Part1.brickColor = BrickColor.new("Cyan")
- Part2.Name = "X"
- Part2.Parent = stand
- Part2.CFrame = CFrame.new(-35.9699898, 2.83500385, 89.9899979, 1, 0, 0, 0, 1, 0, 0, 0, 1)
- Part2.Position = Vector3.new(-35.9699898, 2.83500385, 89.9899979)
- Part2.Color = Color3.new(0.686275, 0.866667, 1)
- Part2.Size = Vector3.new(5, 3.61000061, 2)
- Part2.Anchored = true
- Part2.BottomSurface = Enum.SurfaceType.Smooth
- Part2.BrickColor = BrickColor.new("Pastel light blue")
- Part2.Locked = true
- Part2.TopSurface = Enum.SurfaceType.Smooth
- Part2.brickColor = BrickColor.new("Pastel light blue")
- SurfaceGui3.Parent = Part2
- SurfaceGui3.LightInfluence = 1
- SurfaceGui3.Face = Enum.NormalId.Back
- SurfaceGui3.ClipsDescendants = true
- SurfaceGui3.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
- SurfaceGui3.PixelsPerStud = 50
- SurfaceGui3.SizingMode = Enum.SurfaceGuiSizingMode.PixelsPerStud
- TextBox4.Parent = SurfaceGui3
- TextBox4.Size = UDim2.new(1, 0, 1, 0)
- TextBox4.BackgroundColor = BrickColor.new("Institutional white")
- TextBox4.BackgroundColor3 = Color3.new(1, 1, 1)
- TextBox4.BackgroundTransparency = 1
- TextBox4.Font = Enum.Font.SourceSans
- TextBox4.FontSize = Enum.FontSize.Size14
- TextBox4.Text = "X"
- TextBox4.TextColor = BrickColor.new("Really black")
- TextBox4.TextColor3 = Color3.new(0, 0, 0)
- TextBox4.TextScaled = true
- TextBox4.TextSize = 14
- TextBox4.TextWrap = true
- TextBox4.TextWrapped = true
- Part5.Name = "O"
- Part5.Parent = stand
- Part5.CFrame = CFrame.new(-25.9699898, 2.83500385, 89.9899979, 1, 0, 0, 0, 1, 0, 0, 0, 1)
- Part5.Position = Vector3.new(-25.9699898, 2.83500385, 89.9899979)
- Part5.Color = Color3.new(0.686275, 0.866667, 1)
- Part5.Size = Vector3.new(5, 3.61000061, 2)
- Part5.Anchored = true
- Part5.BottomSurface = Enum.SurfaceType.Smooth
- Part5.BrickColor = BrickColor.new("Pastel light blue")
- Part5.Locked = true
- Part5.TopSurface = Enum.SurfaceType.Smooth
- Part5.brickColor = BrickColor.new("Pastel light blue")
- SurfaceGui6.Parent = Part5
- SurfaceGui6.LightInfluence = 1
- SurfaceGui6.Face = Enum.NormalId.Back
- SurfaceGui6.ClipsDescendants = true
- SurfaceGui6.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
- SurfaceGui6.PixelsPerStud = 50
- SurfaceGui6.SizingMode = Enum.SurfaceGuiSizingMode.PixelsPerStud
- TextBox7.Parent = SurfaceGui6
- TextBox7.Size = UDim2.new(1, 0, 1, 0)
- TextBox7.BackgroundColor = BrickColor.new("Institutional white")
- TextBox7.BackgroundColor3 = Color3.new(1, 1, 1)
- TextBox7.BackgroundTransparency = 1
- TextBox7.Font = Enum.Font.SourceSans
- TextBox7.FontSize = Enum.FontSize.Size14
- TextBox7.Text = "O"
- TextBox7.TextColor = BrickColor.new("Really black")
- TextBox7.TextColor3 = Color3.new(0, 0, 0)
- TextBox7.TextScaled = true
- TextBox7.TextSize = 14
- TextBox7.TextWrap = true
- TextBox7.TextWrapped = true
- Part8.Parent = stand
- Part8.CFrame = CFrame.new(-30.9699936, 6.79000378, 89.4899902, 1, 0, 0, 0, 1, 0, 0, 0, 1)
- Part8.Position = Vector3.new(-30.9699936, 6.79000378, 89.4899902)
- Part8.Color = Color3.new(0.686275, 0.866667, 1)
- Part8.Transparency = 1
- Part8.Size = Vector3.new(15, 3.70000076, 2)
- Part8.Anchored = true
- Part8.BottomSurface = Enum.SurfaceType.Smooth
- Part8.BrickColor = BrickColor.new("Pastel light blue")
- Part8.CanCollide = false
- Part8.Locked = true
- Part8.TopSurface = Enum.SurfaceType.Smooth
- Part8.brickColor = BrickColor.new("Pastel light blue")
- SurfaceGui9.Parent = Part8
- SurfaceGui9.LightInfluence = 1
- SurfaceGui9.Face = Enum.NormalId.Back
- SurfaceGui9.ClipsDescendants = true
- SurfaceGui9.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
- SurfaceGui9.PixelsPerStud = 50
- SurfaceGui9.SizingMode = Enum.SurfaceGuiSizingMode.PixelsPerStud
- maintext.Parent = SurfaceGui9
- maintext.Size = UDim2.new(1, 0, 1, 0)
- maintext.BackgroundColor = BrickColor.new("Institutional white")
- maintext.BackgroundColor3 = Color3.new(1, 1, 1)
- maintext.BackgroundTransparency = 1
- maintext.Font = Enum.Font.SourceSans
- maintext.FontSize = Enum.FontSize.Size14
- maintext.Text = ([[
- Tic Tac Toe
- Choose a player!
- ]])
- maintext.TextColor = BrickColor.new("Really black")
- maintext.TextColor3 = Color3.new(0, 0, 0)
- maintext.TextScaled = true
- maintext.TextSize = 14
- maintext.TextWrap = true
- maintext.TextWrapped = true
- clickX,clickO = Instance.new("ClickDetector"),Instance.new("ClickDetector")
- clickX.Parent = Part2
- clickO.Parent = Part5
- clickX.MaxActivationDistance = 20
- clickO.MaxActivationDistance = 20
- clickX.MouseClick:Connect(function(plr)
- if plr and (plr ~= O and plr ~= X) and not X then
- elseif plr and plr == X then
- X = nil
- TextBox4.Text = "X"
- return
- else
- return
- end
- X = plr
- TextBox4.Text = plr.Name .. "(X) Selected!"
- end)
- clickO.MouseClick:Connect(function(plr)
- if plr and (plr ~= O and plr ~= X) and not O then
- elseif plr and plr == O then
- O = nil
- TextBox7.Text = "O"
- return
- else
- return
- end
- O = plr
- TextBox7.Text = plr.Name .. "(O) Selected!"
- end)
- queue_time()
- playing = true
- set_turn(X)
- end
- function queue_time()
- update([[
- Tic Tac Toe
- Choose a player!
- ]])
- repeat wait(1) until (X and O)
- local _time = start_time
- repeat
- _time -= 1;
- update("Starting in " .. tostring(_time) .. "..")
- wait(1)
- until 0 >= _time or not O or not X
- if not O or not X then
- queue_time()
- else
- clickX:Destroy()
- clickO:Destroy()
- end
- end
- function update(txt)
- if maintext and txt then
- maintext.Text = txt
- end
- end
- function start()
- partfolder:ClearAllChildren()
- plots = {}
- playing = false
- turn = nil
- X = nil
- O = nil
- tid = 0
- total = 0
- prepare()
- make(-37, 0.5, 93)
- end
- start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement