in my server script i have the PlayerAdded
and the PlayerRemoving
events. can i put them in my module script instead hence calling the functions also and would it be a recommended practice? i appreciate any feedback on my code as well - thanks guys
this is my server script:
local plotmanager = require(game.ReplicatedStorage.Scripts.PlotManager)
game.Players.PlayerAdded:Connect(function(player)
plotmanager:GivePlot(player)
plotmanager:SetupUnclaimedPlots()
end)
game.Players.PlayerRemoving:Connect(function(player)
plotmanager:RemovePlot(player)
plotmanager:SetupUnclaimedPlots()
end)
this is my module script:
local BillboardManager = {}
local plots = workspace.Plots
local player = game.Players.LocalPlayer
local PlotSigns = workspace:FindFirstChild("PlotSigns")
function BillboardManager:UpdateClientPlotName()
for _, plot in pairs(plots:GetChildren()) do
if not plot:GetAttribute("owner") then continue end
if plot:GetAttribute("owner") ~= player.UserId then continue end
local PlotTag = plot:FindFirstChild("PlotTag")
if PlotTag and PlotTag:IsA("BillboardGui") then
local frame = PlotTag:FindFirstChild("Frame")
local name = frame:FindFirstChild("name")
local stroke = frame:FindFirstChild("stroke")
if name then name.Text = "Your Plot" end
if stroke then stroke.Text = "Your Plot" end
end
end
end
function BillboardManager:UpdateBillboards()
local character = player.Character or player.CharacterAdded:Wait()
if not character then return end
local HumanoidRootPart = character:FindFirstChild("HumanoidRootPart")
if not HumanoidRootPart then return end
for _, plot in pairs(plots:GetChildren()) do
if not plot:IsA("Model") then continue end
if not plot:GetAttribute("owner") then continue end
if plot:GetAttribute("owner") ~= player.UserId then continue end
local cframe, size = plot:GetBoundingBox()
local distance = (HumanoidRootPart.Position - cframe.Position).Magnitude
local MAX_DISTANCE = (size.X / 2)
local MIN_DISTANCE = MAX_DISTANCE - 6
local PlotTag = plot:FindFirstChild("PlotTag")
if PlotTag and PlotTag:IsA("BillboardGui") then
local frame = PlotTag:FindFirstChild("Frame")
local name = frame.name
local stroke = frame.stroke
if frame then
local alpha = math.clamp((distance - MIN_DISTANCE) / (MAX_DISTANCE - MIN_DISTANCE), 0, 1)
frame.Size = UDim2.new(alpha, 0, alpha, 0)
--print(
-- "min:", distance - MIN_DISTANCE,
-- "max:", MAX_DISTANCE - MIN_DISTANCE,
-- "alpha", alpha
--)
end
end
end
end
return BillboardManager