LUA(Roblox) - 将工具克隆到玩家背包中所需的帮助
因此,我正在用商店制作游戏,而我遇到的问题是,我有一个复制工具,因此当玩家购买该工具时,我可以将其克隆到玩家背包中。问题在于,无论我将其消失的工具放到哪里。我尝试了ServerStorage,ReplicatedStorage,Workspace和脚本内部,但是每次测试游戏时,它都会从任何地方删除它。我会在下面放我的脚本,但我不知道它是否已损坏,我无法对其进行测试,因为该工具可以从我放置的任何地方删除。这是我在Startergui的TextButton中的LocalsScript中的代码。
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
local tool = script.Tool:Clone()
tool.Parent = player.Backpack
print("player recieved tool")
end)
这是从工作空间中的脚本中的一个接触事件触发的。
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
print(hit.Parent)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
game.ReplicatedStorage.Shop:Fire(player)
end
end)
因此,这些可能有效,但我只需要在实际工具消失方面提供帮助即可。任何帮助! (如果您想要图像或视频,我可以记录下来并发送链接)
so I am making a game with a shop and the problem I am having is that I have a tool in ReplicatedStorage so I can clone it into the players backpack when the player buys that tool. The problem is that wherever I put the tool it disappears. I have tried ServerStorage, ReplicatedStorage, Workspace and inside the script but everytime I test the game it removes it from anywhere I put it. I will put my script below but I don't know if that is broken yet, I haven't been able to test it because the tool gets removed from anywhere I put it. Here is my code in a LocalScript in a TextButton in StarterGUI.
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
local tool = script.Tool:Clone()
tool.Parent = player.Backpack
print("player recieved tool")
end)
and that gets triggered from a Touched event in script in a part in Workspace.
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
print(hit.Parent)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
game.ReplicatedStorage.Shop:Fire(player)
end
end)
So, Those might work but I only need help with the actual tool vanishing. Any help appreciated! (If you want images or videos I can record them and send a link)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎问题可能是服务器不知道您获得了该物品,因为它全部在Localside上完成。尝试使用像remoteevent之类的东西。
Localside:
您需要为ReplicatedStorage添加remoteevent。
服务器端:
It seems as the problem might be that the server doesn't know you got the item since it's all done on the localside. Try using something like a RemoteEvent.
Localside:
You'll need to add a RemoteEvent to ReplicatedStorage.
Server side: