【发布时间】:2021-07-05 16:12:06
【问题描述】:
我正在开发一款可以乘船航行的游戏。我的脚本有效,但我想知道我做得对吗?
我想要做的是,一旦你生成了一个靴子,靴子的名称就是用户 ID + 船的名称。 感谢这个论坛上的一个人(非常爱),这很好用! 所以现在我想在其他玩家或玩家自己坐在椅子上将船的名称更改为该玩家名称+船名时,在座位内编写一个脚本。这行得通,但现在我设法得到了玩家的名字,而不是他的 id。我更喜欢玩家的ID。你是怎么做到的?
因为我得到的是玩家的名字而不是他的 id。我不得不再次检查船是否已经存在。现在 1 名玩家可以获得 2 艘船,因为 player.Name 和 player.UserID 不匹配。
所以我的问题是如何从下面的脚本中获取用户 ID 而不是其名称,以便玩家可以接管船但最终不能获得 2 艘船?
我很抱歉我的编码不好,我是新手 :) 感谢您的帮助!
座位内的脚本:
local Seat = script.Parent
local debounceCheck = false
local ChangeBoatName = script.Parent.Parent
local boatname = "ShipOnePerson"
Seat.Changed:Connect(function(player)
if Seat.Occupant ~= nil then
if Seat.Occupant.Parent.Name ~= "PlayerNameHere" then
local PlayerToNewBoat = game.Players:FindFirstChild(Seat.Occupant.Parent.Name)
local Character = PlayerToNewBoat.Character or PlayerToNewBoat.CharacterAdded:Wait()
if not debounceCheck then
-- Is it Occupant?
debounceCheck = true
-- Mark it as Occupant, so that other handlers don't execute
if ChangeBoatName then
local plruserid = Seat.Occupant.Parent.Name
local SetNameToBoat = plruserid..boatname
local NewBoat = ChangeBoatName
NewBoat.Name = SetNameToBoat
NewBoat.Parent = game.Workspace
print(NewBoat)
end
end
else
debounceCheck = false
-- Mark it as not Occupant, so other handlers can execute again
end
else
debounceCheck = false
-- Mark it as not Occupant, so other handlers can execute again
end
end)
我的第二个问题是如何确保在您按下 RegenButton 按钮后,它首先会检查该位置是否已经有船,如果是,我如何确保您无法生成?
下面是按钮 regenbutton 中的代码
local cd = workspace.Regenbutton:WaitForChild('ClickDetector')
local boat = game:GetService('ServerStorage'):WaitForChild('ShipOnePerson')
local button = workspace:WaitForChild('Regenbutton')
local debounce = false
local boatname = "ShipOnePerson"
cd.MouseHoverEnter:Connect(function()
button.Transparency = 0.5
end)
cd.MouseHoverLeave:Connect(function()
button.Transparency = 0
end)
cd.MouseClick:Connect(function(player)
local plruserid = player.UserId
local SetNameToBoat = plruserid..boatname
local plrextraboat = player.Name..boatname
print(SetNameToBoat)
local oldboat = workspace:FindFirstChild(SetNameToBoat)
local oldboat2 = workspace:FindFirstChild(plrextraboat)
if not debounce then
if oldboat then
oldboat:destroy()
end
if oldboat2 then
oldboat2:destroy()
end
debounce = true
local NewBoat = boat:Clone()
NewBoat.Name = SetNameToBoat
NewBoat.Parent = game.Workspace
wait(5)
debounce = false
end
end)
【问题讨论】: