Optimisation Tweens on server side script

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!

Why dont you let the server resolve the slots gotten and send that information to client to create the tweens and see the visuals of the spinning then?

I suppose you are solving the tweens on server side cause the prize indeed should be solved by server, but not the visuals of the machine, that can be sent as instructions to client side to be solved, its just visuals

1 Like

the reason for working on the tweens server side is so that players can see in real time for each player how their slot is spinning, but from your words I can only call an event for each client to produce tweens

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.