Hello! Asking for help with optimizing a script on the server side. This script works for the Slot machine.
I know what Tweens using in server side have a big performance issue so i need help with that.
local TS = game:GetService("TweenService")
local Slot1
local Slot2
local Slot3
local db = false
local TextThing = script.Parent.TName.SurfaceGui.TextLabel
Slots = {
["1"] = {
Image = "http://www.roblox.com/asset/?id=47671241",
CanvasPosition = Vector2.new(0,0)
},
["2"] = {
Image = "http://www.roblox.com/asset/?id=47671036",
CanvasPosition = Vector2.new(0,53.992)
},
["3"] = {
Image = "http://www.roblox.com/asset/?id=47671152",
CanvasPosition = Vector2.new(0,106.992)
},
["4"] = {
Image = "http://www.roblox.com/asset/?id=47671141",
CanvasPosition = Vector2.new(0,159.992)
}
}
local function Reward(Slot1, Slot2, Slot3, Player)
print(Slot1,Slot2,Slot3)
if Slot1 == "1" and Slot2 == "1" and Slot3 == "1" then
Player.Balance.Value += 250
elseif Slot1 == "2" and Slot2 == "2" and Slot3 == "2" then
Player.Balance.Value += 1000
TextThing.Text = "JackPot!!"
task.wait(2.5)
elseif Slot1 == "3" and Slot2 == "3" and Slot3 == "3" then
Player.Balance.Value += 500
elseif Slot1 == "4" and Slot2 == "4" and Slot3 == "4" then
Player.Balance.Value += 750
elseif Slot1 == "1" and Slot3 == "1" or Slot1 == "1" and Slot2 == "1" or Slot2 == "1" and Slot3 == "1" then
Player.Balance.Value += 100
elseif Slot1 == "2" and Slot3 == "2" or Slot1 == "2" and Slot2 == "2" or Slot2 == "2" and Slot3 == "2" then
Player.Balance.Value += 100
elseif Slot1 == "3" and Slot3 == "3" or Slot1 == "3" and Slot2 == "3" or Slot2 == "3" and Slot3 == "3" then
Player.Balance.Value += 100
elseif Slot1 == "4" and Slot3 == "4" or Slot1 == "4" and Slot2 == "4" or Slot2 == "4" and Slot3 == "4" then
Player.Balance.Value += 100
end
TextThing.Text = "Free Slot, Free Win!"
db = false
end
local function ClickOn(Plr)
print("Clicked")
if db then return end
TextThing.Text = Plr.Name.." is playing"
db = true
Slot1 = nil
Slot2 = nil
Slot3 = nil
for i, v in pairs(script.Parent.Parent:GetChildren()) do
if v.Name == "NonePart" then return end
task.spawn(function()
if v.name == "1" then
local Frame = v.SurfaceGui.Frame.ScrollingFrame
Frame.CanvasPosition = Vector2.new(0,0)
local Tw = TS:Create(Frame, TweenInfo.new(0.1,Enum.EasingStyle.Linear,Enum.EasingDirection.In,20,true),{CanvasPosition = Vector2.new(0,159.992)})
Tw:Play()
Tw.Completed:Wait()
local RND = Random.new():NextInteger(1,4)
local WinSlot = Slots[tostring(RND)]
local Tq = TS:Create(Frame, TweenInfo.new(0.1,Enum.EasingStyle.Linear,Enum.EasingDirection.In),{CanvasPosition = WinSlot["CanvasPosition"]})
Tq:Play()
Tq.Completed:Wait()
Slot1 = tostring(RND)
print(Slot1)
elseif v.name == "2" then
local Frame = v.SurfaceGui.Frame.ScrollingFrame
Frame.CanvasPosition = Vector2.new(0,0)
local Tw = TS:Create(Frame, TweenInfo.new(0.1,Enum.EasingStyle.Linear,Enum.EasingDirection.In,30,true),{CanvasPosition = Vector2.new(0,159.992)})
Tw:Play()
Tw.Completed:Wait()
local RND = Random.new():NextInteger(1,4)
local WinSlot = Slots[tostring(RND)]
local Tq = TS:Create(Frame, TweenInfo.new(0.1,Enum.EasingStyle.Linear,Enum.EasingDirection.In),{CanvasPosition = WinSlot["CanvasPosition"]})
Tq:Play()
Tq.Completed:Wait()
Slot2 = tostring(RND)
print(Slot2)
elseif v.name == "3" then
local Frame = v.SurfaceGui.Frame.ScrollingFrame
Frame.CanvasPosition = Vector2.new(0,0)
local Tw = TS:Create(Frame, TweenInfo.new(0.1,Enum.EasingStyle.Linear,Enum.EasingDirection.In,40,true),{CanvasPosition = Vector2.new(0,159.992)})
Tw:Play()
Tw.Completed:Wait()
local RND = Random.new():NextInteger(1,4)
local WinSlot = Slots[tostring(RND)]
local Tq = TS:Create(Frame, TweenInfo.new(0.1,Enum.EasingStyle.Linear,Enum.EasingDirection.In),{CanvasPosition = WinSlot["CanvasPosition"]})
Tq:Play()
Tq.Completed:Wait()
Slot3 = tostring(RND)
print(Slot3)
Reward(Slot1,Slot2,Slot3, Plr)
end
end)
end
end
script.Parent.ClickDetector.MouseClick:Connect(function(plr) ClickOn(plr) end)
Thanks for any help!