So what Im trying to do is spawning boats. It gets the port of the player who triggered the proximity prompt. And it gets it correctly. The problem is, when I set the position of the boat to be at that port’s position. It goes to port of the first player who entered the game(or basically goes to the port which is assigned to first player.)
local proximityPrompt = script.Parent
local boats = game.ServerStorage.Boats:GetChildren()
function getPort(player)
for _, v in pairs(workspace.Ports:GetChildren()) do
if v:IsA("BasePart") then
if v.Name == player.Name then
print(v.Name)
return v
end
end
end
end
proximityPrompt.Triggered:Connect(function(player)
local port = getPort(player)
print(port.Name)
if player.PlayerGui.ShopGUI.Enabled == false then
player.PlayerGui.ShopGUI.Enabled = true
player.Character.HumanoidRootPart.Anchored = true
for _, boat in pairs(boats) do
if boat:GetAttribute("Satilik") and boat:GetAttribute("Fiyat") then
if boat:GetAttribute("Satilik") == true then
local button = game.ServerStorage.GUIElements.Button:Clone()
button.Text = boat.Name.. " - "..boat:GetAttribute("Fiyat").."$"
button.Parent = player.PlayerGui.ShopGUI.MainLabel.ScrollingFrame
button.MouseButton1Down:Connect(function()
if player.leaderstats.Cash.Value >= boat:GetAttribute("Fiyat") or player.leaderstats.Cash.Value == boat:GetAttribute("Fiyat") then
if player.HasBoat.Value == true then
for _, v in pairs(game.Workspace.SpawnedShips:GetChildren()) do
if v.Name == player.Name then
v:Destroy()
player.leaderstats.Cash.Value -= boat:GetAttribute("Fiyat")
local boatC = boat:Clone()
boatC.Name = player.Name
boatC.SensorHitbox.CFrame = port.CFrame
boatC.Parent = workspace.SpawnedShips
player.HasBoat.Value = true
player.PlayerGui.ShopGUI.Enabled = false
for _, button in pairs(player.PlayerGui.ShopGUI.MainLabel.ScrollingFrame:GetChildren()) do
if button:IsA("TextButton") then
button:Destroy()
end
end
player.Character.HumanoidRootPart.Anchored = false
end
end
else
player.leaderstats.Cash.Value -= boat:GetAttribute("Fiyat")
local boatC = boat:Clone()
boatC.Name = player.Name
boatC.SensorHitbox.Position = port.Position
boatC.Parent = workspace.SpawnedShips
player.HasBoat.Value = true
player.PlayerGui.ShopGUI.Enabled = false
for _, button in pairs(player.PlayerGui.ShopGUI.MainLabel.ScrollingFrame:GetChildren()) do
if button:IsA("TextButton") then
button:Destroy()
end
end
player.Character.HumanoidRootPart.Anchored = false
end
else
print("Yeterli nakit yok.")
end
end)
player.PlayerGui.ShopGUI.MainLabel.Exit.MouseButton1Down:Connect(function()
player.PlayerGui.ShopGUI.Enabled = false
for _, button in pairs(player.PlayerGui.ShopGUI.MainLabel.ScrollingFrame:GetChildren()) do
if button:IsA("TextButton") then
button:Destroy()
end
end
player.Character.HumanoidRootPart.Anchored = false
end)
end
else
warn("'Satilik' veya 'Fiyat' degeri eksik.")
end
end
else
player.PlayerGui.ShopGUI.Enabled = false
for _, button in pairs(player.PlayerGui.ShopGUI.MainLabel.ScrollingFrame:GetChildren()) do
if button:IsA("TextButton") then
button:Destroy()
end
end
player.Character.HumanoidRootPart.Anchored = false
end
end)