Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Camera Bugs out during plot selection?

Asked by
0Vyp 14
3 years ago
Edited 3 years ago

So I was following along with Alvin_Block's plot system video. And I came across an error where if there are more than 1 player in the game The selection just doesnt work any more, the selectedtycoon value wont get its default value as well as it wont pan the camera to the tycoon area. Heres the code I have down

Also if its just one player it works perfectly fine

local TweenService = game:GetService("TweenService")

local Player = game.Players.LocalPlayer
local camera = workspace.Camera
camera.CameraType = Enum.CameraType.Scriptable
camera:GetPropertyChangedSignal("CameraType"):Wait()
camera.CameraType = Enum.CameraType.Scriptable

local PlotPicker = script.Parent

local Claim = PlotPicker:WaitForChild("Claim")
local Left = Claim:WaitForChild("Left")
local Right = Claim:WaitForChild("Right")

local SelectedTycoon = Claim:WaitForChild("SelectedTycoon")

local Tycoons = game.Workspace:WaitForChild("Tycoons")

local function findUnoccupiedPlots()
    local availableTycoons = {} 
    for i, Tycoon in pairs(Tycoons:GetChildren()) do
        if Tycoon:GetAttribute("TycoonOwner") == "" then
            table.insert(availableTycoons, Tycoon)
            table.sort(availableTycoons, function(a, b) return a.Name < b.Name end)
        end
    end
    return availableTycoons
end

local TI = TweenInfo.new(
    0.5,
    Enum.EasingStyle.Quint,
    Enum.EasingDirection.InOut,
    0,
    false,
    0
)

local function camTween(tycoon)
    local cf = CFrame.new(tycoon.Ground.Position+Vector3.new(0, 120, 0), tycoon.Ground.Position)
    local tween = TweenService:Create(game.Workspace.Camera, TI, {CFrame = cf})
    tween:Play()
end

local connections = {}

local tycoonsTable = findUnoccupiedPlots()

local index = 1

SelectedTycoon.Value = tycoonsTable[1]
camTween(SelectedTycoon.Value)

connections[#connections+1] = Left.MouseButton1Click:Connect(function()
    if Tycoons:FindFirstChild("Tycoon"..index-1) then
        index -= 1
    else
        index = 4
    end

    SelectedTycoon.Value = tycoonsTable[index]
    camTween(tycoonsTable[index])
end)

connections[#connections+1] = Right.MouseButton1Click:Connect(function()
    if Tycoons:FindFirstChild("Tycoon"..index+1) then
        index += 1
    else
        index = 1
    end

    SelectedTycoon.Value = tycoonsTable[index]
    camTween(tycoonsTable[index])
end)

connections[#connections+1] = Claim.MouseButton1Click:Connect(function()
    local result game:GetService("ReplicatedStorage"):WaitForChild("Remotes").RequestTycoon:InvokeServer(tycoonsTable[index])

    if result then
        Claim.Text = "Successfully Claimed"
    else
        Claim.Text = "Error"
    end

    camera.CameraType = Enum.CameraType.Custom
    PlotPicker.Enabled = false
    SelectedTycoon.Value = nil

    for i,v in pairs(connections) do
        if v then
            v:Disconnect()
        end
    end
end)

Answer this question