I am developing a Roblox game called Train Tycoon. I understand how Studio works, but I know only the basics of scripting. I am now adding the key feature of the game: Crate deliveries. I tryed out by modifying the script you can get from the tutorial about tools in the Roblox Wiki.
The WoodCrate is the object i'm trying to pick up here
-- LocalScript local tool = script.Parent local player = game.Players.LocalPlayer local mouse = player:GetMouse() local model = game.Workspace.WoodCrate local clickEvent = tool.ClickEvent local function onActivate() local clickLocation = mouse.Hit clickEvent:FireServer(clickLocation) end tool.Activated:connect(onActivate)
-- Server (normal) Script local tool = script.Parent local clickEvent = tool.ClickEvent local clickEventConnection local model = game.Workspace.WoodCrate local function onClick(player, clickLocation) if clickLocation:FindFirstChild(model) then model.Parent = tool end end local function onEquip() clickEventConnection = clickEvent.OnServerEvent:connect(onClick) end local function onUnequip() clickEventConnection:disconnect() end tool.Equipped:connect(onEquip) tool.Unequipped:connect(onUnequip)
Sadly, it doesn't work. The crate should be able to be moved by a player and put in the train's cart and be drived around. Also, I want the crate to stay at the place where I put it when the train is moving. I don't want to risk encountering bugs similar to those in Lumber Tycoon 2. I would like help about that too. That has been done in Tradelands, where crates stick at a designated spot in a ship. that would be great to have. if that's of any help, trains in my game are just like normal cars, they don't have a script to move them. Thanks in advance for any help.