【发布时间】:2020-10-17 09:53:26
【问题描述】:
我最近开始在 roblox 中与朋友一起制作我的第一款游戏。我正在编写某种盒子,这样当你触摸它时,它就会给你某种枪。我尝试了一些随机调整,但从未奏效。这是我的代码: 它所做的是等待玩家触摸它,然后执行动画(我已将其插入脚本),然后生成一个随机数。根据随机数,它决定给玩家什么。然后它会破坏箱子,所以玩家不能一遍又一遍地刷箱子。
math.randomseed(tick())
script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
script.Disabled = true
local player = hit.Parent.Name
local num = 0
for i = 1,45 do
wait()
script.Parent.CFrame = ( CFrame.new(script.Parent.Position) * CFrame.Angles(0,math.rad(num),0) )
script.Parent.Part.CFrame = ( CFrame.new(script.Parent.Part.Position) * CFrame.Angles(0,math.rad(num),0) )
end
num = 0
num = math.random(0,100)
if num>-1 and num<5 then
local sword1 = game.ServerStorage.XM1404:Clone()
sword1.Parent = game.Players[player].Backpack
elseif num<10 then
local sword1 = game.ServerStorage.MP5:Clone()
sword1.Parent = game.Players[player].Backpack
elseif num<15 then
local sword1 = game.ServerStorage.SPAS12:Clone()
sword1.Parent = game.Players[player].Backpack
elseif num<20 then
local sword1 = game.ServerStorage.M9:Clone()
sword1.Parent = game.Players[player].Backpack
elseif num<25 then
local sword1 = game.ServerStorage.M4A1:Clone()
sword1.Parent = game.Players[player].Backpack
elseif num<30 then
local sword1 = game.ServerStorage.M32:Clone()
sword1.Parent = game.Players[player].Backpack
elseif num<35 then
local sword1 = game.ServerStorage.GC:Clone()
sword1.Parent = game.Players[player].Backpack
elseif num<44 then
local sword1 = game.ServerStorage.Riot Shield:Clone()
sword1.Parent = game.Players[player].Backpack
elseif num<60 then
local sword1 = game.ServerStorage.Grenade:Clone()
sword1.Parent = game.Players[player].Backpack
elseif num<65 then
local sword1 = game.ServerStorage.M60:Clone()
sword1.Parent = game.Players[player].Backpack
elseif num<70 then
local sword1 = game.ServerStorage.AUG:Clone()
sword1.Parent = game.Players[player].Backpack
elseif num<90 then
local sword1 = game.ServerStorage.PartHP:Clone()
sword1.Parent = game.Players[player].Backpack
elseif num<93 then
local sword1 = game.ServerStorage.RocketL:Clone()
sword1.Parent = game.Players[player].Backpack
elseif num<97 then
local sword1 = game.ServerStorage.Max Heal Potion:Clone()
sword1.Parent = game.Players[player].Backpack
elseif num<98 then
local sword1 = game.ServerStorage.DaggerOfShattereedDimensions:Clone()
sword1.Parent = game.Players[player].Backpack
elseif num<100 then
local sword1 = game.ServerStorage.Pulse:Clone()
sword1.Parent = game.Players[player].Backpack
end
script.Parent:Destroy()
end
end)
所有枪支都在服务器存储中
【问题讨论】:
-
对不起,但它不起作用:(
-
“不起作用”是什么意思?期望的结果是什么?会发生什么?
-
期望的结果是箱子应该给玩家(触摸箱子)随机生成的枪然后消失。发生的情况是,当玩家触摸它时,什么也没有发生。它就像一个用于装饰的道具/盒子。
-
这些东西都是
Tools吗? -
是的,我在问之前确定了。