Hi,
I have an admin command that is used to spawn items onto the workspace. In studio it works fine but not online. Essentially, what it does is that you type a command inside a textbox, and when you press enter the object spawns in your inventory. When I take it out of the inventory however, the item is nil. The following is a sample of my code:
local textBox= Instance.new("TextBox",adminGui) textBox.Name= "TextBox" textBox.Text= "Admin Commands" textBox.Position= UDim2.new(0,0,0.9,0) textBox.Size= UDim2.new(0.2,0,0.1,0) function onKeyPress(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.Return then local theText= textBox.Text if theText== "adminroom" then game.Players.LocalPlayer.Character.Torso.CFrame = CFrame.new(workspace.AdminRoom.AdminRoomBase.BaseBottom.Position+Vector3.new(0,5,0)) elseif theText== "room" then game.Players.LocalPlayer.Character.Torso.CFrame= CFrame.new(workspace["Pool of Oil"].Position+Vector3.new(1100,50,100)) elseif theText== "stats50" then game.StarterGui.Hunger.HungerValue.Value= 50 game.StarterGui.Health.HealthValue.Value= 50 game.StarterGui.Thirst.ThirstValue.Value= 50 elseif theText== "stats100" then game.StarterGui.Hunger.HungerValue.Value= 100 game.StarterGui.Health.HealthValue.Value= 100 game.StarterGui.Thirst.ThirstValue.Value= 100 elseif theText== "Handle" then local cloneObj= game.ReplicatedStorage:FindFirstChild("Handle",true):Clone() cloneObj.Parent= game.StarterGui.Inventory.Itembag end end end game:GetService("UserInputService").InputBegan:connect(onKeyPress)
The following script takes the item from the backpack to the workspace:
local Player= game.Players.LocalPlayer local Mouse= Player:GetMouse() function onLeftButtonDown() game.Players.LocalPlayer.PlayerGui.InventoryGui.Enabled= false local foundItem= game.StarterGui.Inventory.Itembag:FindFirstChild(tostring(script.Parent.Text)) if foundItem then local function onMouseMove() --game.StarterGui.Inventory.CheckMoving.Value= 1 local mouseHitX= Mouse.Hit.X --local mouseHitY= game.Players.LocalPlayer.Character.Torso.Position.Y local mouseHitY= game.Players.LocalPlayer.Character:FindFirstChild("Left Leg").Position.Y local mouseHitZ= Mouse.Hit.Z found.Position= Vector3.new(Mouse.Hit.X,Mouse.Hit.Y,Mouse.Hit.Z) local function onLeftButtonDown2() found.Position= Vector3.new(found.Position.X,found.Position.Y,found.Position.Z) if not Mouse.Target then return end local mouseTarget= Mouse.Target if mouseTarget.CanCollide== false and mouseTarget.Anchored== true and mouseTarget.Transparency== 0.5 then mouseTarget.Transparency= 0 mouseTarget.CanCollide= true mouseTarget.Anchored= false game.Players.LocalPlayer.PlayerGui.InventoryGui.Enabled= true script.Parent:Destroy() end end Mouse.Button1Down:connect(onLeftButtonDown2) end Mouse.Move:connect(onMouseMove) end end script.Parent.MouseButton1Down:connect(onLeftButtonDown)
My attempt was to use an external function that will loop the command until it goes into the workspace, and call it after ``:
function Loop() if cloneObj.Parent~= workspace then while cloneObj.Parent~= workspace then wait() cloneObj.Parent= workspace end end end
This pertains specifically to the object called 'Handle'.
Thanks, Houlardy