So im making something for when you press E on an object it will pick it up but if i pick up all of the objects then my friend in the server can still pick up the same ones as i picked up im thinking its something to do with that i have a Bindable Event for communicating between two local scripts. I think the fix will be to convert one of the scripts to a server but i dont know which one or how.
First Script :
local UIS = game:GetService("UserInputService")
local pickupHotkey = "E"
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local PlayerGUI = plr:WaitForChild("PlayerGui")
local PickupGUI = PlayerGUI:WaitForChild("PickUpGUI")
local Slot1EventWood = game.ReplicatedStorage.Slot1Wood
UIS.InputChanged:Connect(function(input)
if mouse.Target then
if mouse.Target:FindFirstChild("Pickup") then
local item = mouse.Target
PickupGUI.Adornee = item
PickupGUI.ObjectName.Text = item.Name
PickupGUI.Enabled = true
else
PickupGUI.Adornee = nil
PickupGUI.Enabled = false
end
end
end)
UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode[pickupHotkey] then
if mouse.Target then
if mouse.Target:FindFirstChild("Pickup")then
local item = mouse.Target
if item then
local distanceFromItem = plr:DistanceFromCharacter(item.Position)
if distanceFromItem < 20 then
if item.Name == "Wood" then
Slot1EventWood:FireServer()
end
end
end
end
end
end
end)
Second script :
--//Variables\\--
local plr = game.Players.LocalPlayer
local Slot1EventWood = game.ReplicatedStorage.Slot1Wood
local mouse = plr:GetMouse()
local item = mouse.Target
Slot1EventWood.Event:Connect(function()
print("Client Received the Event")
if script.Parent.QuantitiyVal == 1 then
print("No room >:)")
if script.Parent.Item == "Wood" then
print("Room due to stacking")
elseif script.Parent.QuantitiyVal == 99 then
print("No room due to max stack limit")
end
else
if item.Name == "Wood" then
item:Destroy()
end
print("Room")
script.Parent.Item.Value = "Wood"
script.Parent.QuantitiyVal.Value = script.Parent.QuantitiyVal.Value + 1
script.Parent.Visible = true
script.Parent.Quantity.Text = script.Parent.QuantitiyVal.Value
end
end)

10 comments
Theres an error message saying : 09:43:30.008 - Players.EhEhEhEhLPKJ.PlayerGui.InventoryGUI.MainFrame.Slot1.Script:5: attempt to index nil with 'Target'
Edited the code above. Thank you @iuclds for correcting me. the "local mouse = plr:GetMouse()" needs to be inside the Event though otherwise you'll get an error.
It seems to still be saying the same thing just this time for line 7
@xInfinityBear
You could try a repeat wait as well, don't know if it will work, but i guess you could try it. I'll edit the code above.
Just edited my answer, hopefully it works.
:( sorry it still doesn't
I could try make a separate answer to do with that bug
Damn dude, that sucks. I can't think of anything else, so yea make a separate answer with that issue and hopefully someone helps you with it.
alr