Roblox Lua 给LocalPlayer赠送武器无法工作

我的代码:https://justpaste.it/87evk

local original = game:GetService("ReplicatedStorage"):FindFirstChild("CloneSmoke")

local tool = script.Parent
local copy = original:Clone()

tool.Activated:Connect(function()
print("Running...")
local sound = script.Parent.Sound

copy.Parent = script.Parent.Handle
sound:Play()
wait(3)
tool:Destroy()
local plr = game.Players.LocalPlayer
local weapon = game.ReplicatedStorage.Jutsus.Momoshiki["Momoshikis Sword"]
local w2 = weapon:Clone()
w2.Parent = plr.Backpack
end)

不知道我要在这里做什么才能给玩家赠送武器。我尝试了很多,但没找到正确的解决方案。

如果你能帮我就好了

点赞
用户15250066
用户15250066

首先,确保这是在本地脚本中。

同时将local original = game:GetService("ReplicatedStorage"):FindFirstChild("CloneSmoke")改为local original = game:GetService("ReplicatedStorage"):WaitForChild("CloneSmoke")。这是因为脚本加载速度比游戏中的物品快,所以很有可能剑还没有加载到游戏中,脚本运行时找不到你要引用的对象,脚本就无法工作。

2021-05-01 00:12:06