In making some inventory system that i can pick up items on the ground ,when im close enough i can click "E" to pick up the item, the item is then added in my inventory and should be removed from the workspace, The problem here is to remove the item from workspace i'd use Mouse.Target:Destroy() but now i can't use it from the serverScript. How could i do this?
Heres the LocalScript to pick up item
local player = game:GetService("Players").LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Mouse = player:GetMouse()
Mouse.KeyDown:connect(function(key)
key = key:lower()
if ( key == "e") then
local pos1 = Mouse.Target.Position
local pos2 = player.Character.Torso.Position
local magnitude = (pos1 - pos2).magnitude
local removeItemEvent = ReplicatedStorage:WaitForChild("RemoveItemEvent")
if magnitude <=6 and Mouse.Target.Parent:FindFirstChild("Type") then
local name = Mouse.Target.Parent
local id = Mouse.Target.Parent.ID
local inv = player.PlayerGui.UI.Right.Inventory.Inv
local Type = Mouse.Target.Parent.Type
if inv.Items.Value < 12 then
inv.Items.Value = inv.Items.Value + 1
local button = inv.ImageButton:Clone()
button.Name = name.Name
button.Parent = inv
button.ItemType.Value = Type.Value
button.Visible = true
--button.Image = id.Value
removeItemEvent:FireServer()
print(Mouse)
end
end
end
end)
here's the serverScript that sould remove the item from the workspace so everyone on the server see it getting removed.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local removeItemEvent = ReplicatedStorage.RemoveItemEvent
local function onRemoveItemFired(player)
player = game:GetService("Players"):FindFirstChild(player.Name)
local Mouse = player:GetMouse()
print(player,Mouse.Target)
Mouse.Target.Parent:Destroy()
end
removeItemEvent.OnServerEvent:Connect(onRemoveItemFired)

2 comments
ohh i think i got it! thanks!
Yw. Feel free to accept the answer if you've found it helpful!