#Equiping a tool using remote events

1 messages · Page 1 of 1 (latest)

halcyon sorrel
#

How can i achieve this, i already tried to match names but i had two issues, first the name matching just didnt work even tho it was the same and also tools may have the same name but look different in my game. Im guessing you can not pass objects though remote events so im not sure what to do?

sinful gate
spiral hatch
halcyon sorrel
#

i tried to

#

nothing is working

spiral hatch
#

you can do it if it exists on server and client ig

halcyon sorrel
#

thats waht i done

#

let me send

#

Local script in gui, so the Tool.Value is a object value that holds the tool

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local equipToolEvent = ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("EquipToolEvent")

local player = game.Players.LocalPlayer

local Tool = script.Parent.Parent.CurrentEquipedTool
local button = script.Parent

button.MouseButton1Click:Connect(function()
    equipToolEvent:FireServer(Tool.Value)
end)```
Handler
```lua
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ToolManager = require(ReplicatedStorage:WaitForChild("ToolManager"))
local remote = ReplicatedStorage.Remotes:WaitForChild("EquipToolEvent")

remote.OnServerEvent:Connect(function(player, tool)
    print("Recieved")
    ToolManager:EquipTool(player, tool)
end)

/

local ToolManager = {}

function ToolManager:EquipTool(player, tool)
    print("Tool Manager Runned")

    local character = player.Character or player.CharacterAdded:Wait()
    local backpack = player:FindFirstChild("Backpack")
    if not backpack then 
        warn("No backpack found")
        return 
    end

    for _, item in ipairs(character:GetChildren()) do
        if item:IsA("Tool") and item ~= tool then
            item.Parent = backpack
        end
    end

    tool.Parent = character
    print("Equipped:", tool.Name)
end

return ToolManager
spiral hatch
sinful gate
#

fr tho

spiral hatch
#

makes sense

halcyon sorrel
#

yeah

#

i didnt think i was tripping

halcyon sorrel
#

oh right also

#

23:25:42.829 ReplicatedStorage.ToolManager:23: attempt to index nil with 'Parent' - Server - ToolManager:23

#

i got a error

spiral hatch
#

put print(tool)

#

also where is the tool

halcyon sorrel
#

comes in the function

spiral hatch
#

where is it

#

ReplicatedStorage

#

ServerStorage

halcyon sorrel
#

good point let me check

#

tool.Parent = player:WaitForChild("Backpack")

#

so in the players backpack

#

only thing is

#

i made that with a local script

#

i just saw

#

i made the tool with a local script

#

thats not gonna work

spiral hatch
#

yeep

halcyon sorrel
#

thats why

spiral hatch
#

server doesnt see it

halcyon sorrel
#

yeah right that makes more sense

#

okay one sec

#

i fixed it thanks

#

@spiral hatch can i ask smth else rq

#

i get this error when i try to clear the children of my scrolling frame but idk why 23:54:38.725 Players.Teddy_arm.PlayerGui.Inventory.InventoryFrame.ScrollingFrame.InventoryController:4: attempt to index nil with 'Parent' - Studio

    local scrollingFrame = script.Parent.Parent.ScrollingFrame
    local InspectFrame = script.Parent.Parent.InspectFrame
    scrollingFrame:ClearAllChildren()```
spiral hatch
#

debug it with prints