Hello everyone, I’m new to scripting, I want to ask you if there’s any way to simplify my code? To make it simpler. What the script does is shown in the video.
module Script
local module = {}
local workSpace = game:GetService("Workspace")
local Player = game:GetService("Players")
local ts = game:WaitForChild("TweenService")
local player = Player.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local Gui = player.PlayerGui:WaitForChild("MainGui")
local TradeFrame = Gui.Trade.TradeFrame
local camera = workSpace.CurrentCamera
local EstimateText = TradeFrame.TextEstimate
local OfferText = TradeFrame.TextOffer
local NameText = TradeFrame.TextName
local ItemFolder = workSpace:WaitForChild("ItemFolder")
local ItemName = {"chest", "flower", "lamp", "paper", "pan", "knife", "cup", "plate", "pot", "key", "book", "pillow", "fence", "woodenBox", "woodBox", "box"}
local ItemPrice = {1000, 970, 950, 1100, 550, 560, 530, 570, 500, 520, 250, 230, 220, 260, 270, 300}
local ItemRot = {-90, 180, -90, 180}
local ItemRandom
local ItemClone
local ItemPos = {}
local PlrPos = {}
local CameraPos = {}
for i = 1, 4 do
ItemPos[i] = workSpace:WaitForChild("ItemPos"..i)
PlrPos[i] = workSpace:WaitForChild("PlrPos"..i)
end
function module.ItemGen(CurrentPlr)
character:PivotTo(PlrPos[CurrentPlr].CFrame)
humanoid.WalkSpeed = 0
humanoid.JumpHeight = 0
camera.CameraType = Enum.CameraType.Scriptable
CameraPos = ItemPos[CurrentPlr].CFrame * CFrame.new(0, 0, 3) * CFrame.new(0, 1.5, 0) * CFrame.Angles(math.rad(-15), 0, 0)
ts:Create(camera, TweenInfo.new(0.5), {CFrame = CameraPos}):Play()
if ItemClone ~= nil then
ItemClone:Destroy()
end
ItemRandom = math.random(1, #ItemName)
for i, child in pairs(ItemFolder:GetChildren()) do
if child.Name == ItemName[ItemRandom] then
ItemClone = child:Clone()
ItemClone.Parent = workSpace
ItemClone:MoveTo(ItemPos[CurrentPlr].Position)
ItemClone:PivotTo(ItemClone:GetPivot() * CFrame.Angles(0, math.rad(ItemRot[CurrentPlr]), 0))
end
end
end
return module
Local Script
local Replic = game:GetService("ReplicatedStorage")
local Gui = script.Parent.Parent
local But = script.Parent.TextButton
local CurrentPlr
local remotePlr = Replic.remote.remotePlr
local moduleItem = require(Replic.module.ModuleItem)
local IteGen = moduleItem.ItemGen
remotePlr.OnClientEvent:Connect(function(i)
CurrentPlr = i
end)
But.MouseButton1Click:Connect(function()
IteGen(CurrentPlr)
end)