You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
Give a npc a tool on pressing a button -
What is the issue? Include screenshots / videos if possible!
it prints “Given” but no tool is given until after the 2nd time you press the equip button
Better Explanation here:
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Devfourms
Code:
local ActionOrMovement = game.ReplicatedStorage.Remotes.ActionOrMovement
local tool = script.ClassicSword
ActionOrMovement.OnServerEvent:Connect(function(player, player2, Input)
local HRP = player2:FindFirstChild("HumanoidRootPart")
if Input == "ButtonY" then
if player2:FindFirstChild("ClassicSword") then
player2.ClassicSword:Destroy()
warn("Cleared")
else
local newSword = tool:Clone()
newSword.Parent = player2
warn("given")
end
Client script if you even needed it:
uis.InputBegan:Connect(function(Input, gameProcessed)
local newInput = Input.KeyCode.Name
if newInput == "ButtonY" then
game.ReplicatedStorage.Remotes.ActionOrMovement:FireServer(player2, newInput)
game.ReplicatedStorage.Remotes.SwordEquip:FireServer()