【发布时间】:2021-04-06 12:02:12
【问题描述】:
所以我正在尝试制作一个游戏,在本地脚本中的StarterCharacterScripts 中触摸名为WinPad 的部分以触发事件,该事件在聊天中发送消息,并将PostAsync() 发送到不和谐网络钩子。但是,在触发事件时,它会给出错误attempt to concatenate Instance with string,即使所有传入的参数都是字符串。这是 LocalScript 中的事件触发程序:
local name = tP:FindFirstChild("TowerName")
local diff = tP:FindFirstChild("Difficulty")
local diffid = tP:FindFirstChild("DifficultyId")
local diffcolor = tP:FindFirstChild("DiffColor3")
game.ReplicatedStorage.WinEvent:FireServer(game.Players.LocalPlayer.Name, name.Value, diff.Value, diffid.Value, diffcolor.Value)
这是OnServerEvent:Connect() 脚本:
game.ReplicatedStorage.WinEvent.OnServerEvent:Connect(function(plr, towername, towerdiff, towerdiffid, color)
local HookData = {
['content'] = "**"..plr.."** has beaten **"..tostring(towername).." [<:"..tostring(towerdiff)..":"..tostring(towerdiffid)..">]**."
}
HookData = http:JSONEncode(HookData)
http:PostAsync(url, HookData)
plr.Parent:MoveTo(Vector3.new(-764, 12.5, -54.5))
createSystemMessage:FireAllClients((plr.." has beaten "..towername.."."), color, Enum.Font.SourceSansBold, Enum.FontSize.Size14)
end)
另外,tP 是被LocalPlayer.Character.Humanoid 触及的部分
【问题讨论】:
-
另外,在 LocalScript 中使用
WaitForChild()也不起作用。 -
您说所有都是字符串,但您使用
plr作为表格plr.Parent:MoveTo(Vector3.new(-764, 12.5, -54.5))并尝试将其连接到您的HookData['content']字符串中。 -
我添加了
local player = plr并将plr.Parent:MoveTo()更改为player:MoveTo()并返回相同的错误。 -
如果
plr是玩家桌,您需要将['content'] = "**"..plr.."**更改为能获得名称的东西。 -
在 LocalScript 中它已经调用了 LocalPlayer 的 Name 属性。
标签: lua webhooks roblox httpservice