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)
Okay, so the item is the thing you want to destroy on the server? if so doing it in a local script wont work as it's only destroying it for the client. Anyway, you should use a RemoteEvent to fire the server from the local script then copy the code from the second script and paste it into a Server Script, and use Event.OnServerEvent()
First Script (Local 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 (Server Script):
local Slot1EventWood = game.ReplicatedStorage.Slot1Wood Slot1EventWood.OnServerEvent:Connect(function(plr) local mouse = plr:GetMouse() repeat wait() until mouse.Target ~= nil local item = mouse.Target 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)
Hopefully this works. If this isn't what you were asking for just post a comment below and I'll try to help you.
for xInfinityBear
local Slot1EventWood = game.ReplicatedStorage.Slot1Wood local mouse = plr:GetMouse() Slot1EventWood.OnServerEvent:Connect(function(plr) if mouse.Target == nil then return end local item = mouse.Target 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)