制作衣服GUI

时间:2019-02-22 21:43:07

标签: lua roblox

当角色单击按钮时,我将尝试制作一个GUI(在roblox工作室中),将为他或她提供服装。

ServerScriptService代码

local Event = Instance.new("RemoteEvent")
Event.Parent = game.ReplicatedStorage
Event.Name = "UniformGiveEvent"
local Shirt = "rbxassetid://182645836"
local Pants = "rbxassetid://824967650"

function GiveUni(plr)
    local character = plr.Character
    local shirt = character.Shirt
    local pants = character.Pants
    shirt.ShirtTemplate = Shirt
    pants.PantsTemplate = Pants
end

Event.OnServerEvent:Connect(GiveUni)

GUI本地脚本

local button = script.Parent.GiveUniform
local debounce = true
local UniEvent = game.ReplicatedStorage:WaitForChild("UnifromGiveEvent")

button.MouseButton1Click:Connect(function()
    if debounce then
         debounce = false
         UniEvent:FireServer()
    end
 end)

2 个答案:

答案 0 :(得分:2)

Event.Name = "UniformGiveEvent"
local UniEvent = game.ReplicatedStorage:WaitForChild("UnifromGiveEvent")

至少,您的事件名称和正在等待的孩子的名称上有一个简单的错字。 (Unif mGiveEvent / Unif ro mGiveEvent)

答案 1 :(得分:1)

启动服务器时,尚未将播放器发送到服务器。您没有函数(GiveUni)所需的参数(播放器)。

要解决此问题,只需更改这两行;

button.MouseButton1Click:Connect(function() 

button.MouseButton1Click:Connect(function(player)

UniEvent:FireServer()

UniEvent:FireServer(player)