Skip to content

Instantly share code, notes, and snippets.

View MajorTal's full-sized avatar

Tal Weiss MajorTal

View GitHub Profile
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local ShopItems = require(ServerStorage.ShopItems)
local buyItemEvent = ReplicatedStorage:WaitForChild("BuyItemEvent")
buyItemEvent.OnServerEvent:Connect(function(player, itemType)
local itemDef = ShopItems[itemType]
if not itemDef then
warn("Unknown item:", itemType)
local tool = script.Parent
local event = game.ReplicatedStorage:WaitForChild("GlobalPlaceRequest")
local itemType = tool:WaitForChild("ItemType").Value
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
tool.Activated:Connect(function()
if mouse.Target then
local position = mouse.Hit.p
event:FireServer(itemType, position)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local ShopItems = require(ServerStorage.ShopItems)
local function snapToGrid(position, gridSize)
return Vector3.new(
math.floor(position.X / gridSize + 0.5) * gridSize,
position.Y,
math.floor(position.Z / gridSize + 0.5) * gridSize
)
local function savePoles(player)
local roomName = player:GetAttribute("Room")
local room = workspace.PlayerRooms:FindFirstChild(roomName)
if not room then return end
local polesData = {
poles = {},
roomCenter = {
x = room.Position.X,
y = room.Position.Y,
local function loadPoles(player)
local previousDataSuccess, polesData = pcall(function()
return poleDataStore:GetAsync(player.UserId)
end)
if not previousDataSuccess or not polesData then
warn("No previous poles data found for player:", player.Name)
return
end
local DataStoreService = game:GetService("DataStoreService")
local poleDataStore = DataStoreService:GetDataStore("PolePlacementData")
local Players = game:GetService("Players")
local GRID_SIZE = 4 -- Same grid size you used earlier
-- Helper to snap positions
local function snapToGrid(position)
return Vector3.new(
local function restackPolesAtPosition(deletedPolePosition, room)
local polesAtPos = {}
-- Find poles at same X,Z position
for _, pole in ipairs(room:GetChildren()) do
if pole:IsA("BasePart") then
if math.abs(pole.Position.X - deletedPolePosition.X) < 0.1 and math.abs(pole.Position.Z - deletedPolePosition.Z) < 0.1 then
table.insert(polesAtPos, pole)
end
end
local tool = script.Parent
local deleteRequest = tool:WaitForChild("DeleteRequest")
local function poleBelongsToPlayerRoom(pole, player)
local roomName = player:GetAttribute("Room")
local playerRoom = workspace.PlayerRooms:FindFirstChild(roomName)
return playerRoom and pole:IsDescendantOf(playerRoom)
end
deleteRequest.OnServerEvent:Connect(function(player, targetPole)
local tool = script.Parent
local deleteRequest = tool:WaitForChild("DeleteRequest")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
tool.Activated:Connect(function()
if mouse.Target and mouse.Target:IsA("BasePart") then
deleteRequest:FireServer(mouse.Target)
end
end)
local tool = script.Parent
local placeRequest = tool:WaitForChild("PlaceRequest")
local GRID_SIZE = 4 -- Grid snapping size
local function snapToGrid(position, gridSize)
return Vector3.new(
math.floor(position.X / gridSize + 0.5) * gridSize,
position.Y,
math.floor(position.Z / gridSize + 0.5) * gridSize