Hello,how can i make a system when you click on a player it will your current tool white u equipping it?
Example:You have a case,you click on another player while u keeping it and it will parent your case to the player that you clicked
Hello,how can i make a system when you click on a player it will your current tool white u equipping it?
Example:You have a case,you click on another player while u keeping it and it will parent your case to the player that you clicked
Not trying to be mean, but can you explain?
he means like, whenever you click a player in-game, you give your equipped tool to them
You need to create one RemoteEvent
to make editions to the server make the RemoteEvent
name to GiveTool
. First things first, creat a LocalScript
and put it inside of a Tool
, where the LocalScript
’s parent is the Tool
.
The LocalScript
for the tool to initiate the client control:
-- Tool Variable
local tool = script.Parent
-- Player Variables
local players = game:GetService("Players")
local player = players.LocalPlayer
local mouse = player:GetMouse()
-- ReplicatedStorage Variables
local rs = game:GetService("ReplicatedStorage")
local giveTool = rs.GiveTool
-- This function checks if the tool is equiped and if the equipedTool instance = the tool instance,
-- and then checks if the mouse target is a humanoid, and then launched an event
mouse.Button1Down:Connect(function() -- Mouse Click Event
local EquipTool = player.Character:FindFirstChildOfClass("Tool") -- Finding the instance of the equipped tool
if not EquipTool then return end -- Checks if tool is equipped
if EquipTool ~= tool then return end -- Checks if the equipped tool instance is the same instance as the tool
if mouse.Target.Parent:FindFirstChild("Humanoid") then -- checks if the mouse hit a humanoid/player
giveTool:FireServer(players:GetPlayerFromCharacter(mouse.Target.Parent), tool) -- fire the server event
end
end)
Then you will need to create a script inside of the ServerScriptService
, name it whatever you want and put this code in it.
Script
:
-- ReplicatedStorage Variables
local rs = game:GetService("ReplicatedStorage")
local giveTool = rs.GiveTool
-- Gives the tool to the other player, then deletes the tool
giveTool.OnServerEvent:Connect(function(player, player2, tool: Tool)
local clonedTool = tool:Clone() -- Clones the tool
clonedTool.Parent = player2.Backpack -- Puts the cloned tool in the player2's backpack
tool:Destroy() -- Destroys the old tool
end)
Last update added comments explaining why I did what I did.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.