Workspace.SCP.Folder.Tool giver [Proximity Prompt].ProxPart.ProximityPrompt.Script:35: attempt to call a string value - Server - Script:35
is it this line
local Tool = Storage:FindFirstChild(ToolName(nahoda))
??? !!!
print(nahoda)
is it for control random number for me, its OK. Everytime, when I press button, genered numbers between 1 to 16.
local ToolName1 = {"AKM"}
local ToolName2 = {"AR2"}
local ToolName3 = {"Barret"}
local ToolName4 = {"CM4A1"}
local ToolName5 = {"Dixie"}
local ToolName6 = {"FN-FAL"}
local ToolName7 = {"Ithaca37"}
local ToolName8 = {"Keycard Level 1"}
local ToolName9 = {"Keycard Level 2"}
local ToolName10 = {"Keycard Level 3"}
local ToolName11 = {"Keycard Level 4"}
local ToolName12 = {"Keycard Level 5"}
local ToolName13 = {"Keycard Level 6"}
local ToolName14 = {"Keycard Level 7"}
local ToolName15 = {"Keycard Level 8"}
local ToolName16 = {"Keycard Level 9"}
local Storage = game.ServerStorage.Tools
local Settings = script.Settings
local Cas1 = Settings["Cas1"].Value
local Cas2 = Settings["Cas2"].Value
local Part = script.Parent.Parent
local ProximityPrompt = script.Parent
ToolName = {}
ProximityPrompt.Triggered:connect(function(Player)
if Player and Player.Character then
local Backpack = Player:WaitForChild("Backpack")
local nahoda = math.random(1,16)
print(nahoda)
local Tool = Storage:FindFirstChild(ToolName(nahoda))
if Tool then
Tool:clone().Parent = Backpack
end
end
Part.ProximityPrompt.Enabled = false
Part.CanCollide = false
Part.Transparency = 1.0
Part.CanTouch = false
wait(math.random(Cas1, Cas2))
Part.CanCollide = true
Part.Transparency = 0.0
Part.CanTouch = true
Part.ProximityPrompt.Enabled = true
end)
local ToolName1 = "AKM"
local ToolName2 = "AR2"
local ToolName3 = "Barret"
local ToolName4 = "CM4A1"
local ToolName5 = "Dixie"
local ToolName6 = "FN-FAL"
local ToolName7 = "Ithaca37"
local ToolName8 = "Keycard Level 1"
local ToolName9 = "Keycard Level 2"
local ToolName10 = "Keycard Level 3"
local ToolName11 = "Keycard Level 4"
local ToolName12 = "Keycard Level 5"
local ToolName13 = "Keycard Level 6"
local ToolName14 = "Keycard Level 7"
local ToolName15 = "Keycard Level 8"
local ToolName16 = "Keycard Level 9"
local nastroj -- nastroj is word in czech language for tool
local Storage = game.ServerStorage.Tools
local Settings = script.Settings
local Cas1 = Settings["Cas1"].Value
local Cas2 = Settings["Cas2"].Value
local Part = script.Parent.Parent
local ProximityPrompt = script.Parent
ProximityPrompt.Triggered:connect(function(Player)
if Player and Player.Character then
local Backpack = Player:WaitForChild("Backpack")
-- here generate random numbers
local nahoda = math.random(1,12) --nahoda is word in czech language for random
-- simplify this code
if nahoda == 1 then
nastroj = ToolName1
elseif nahoda == 2 then
nastroj = ToolName2
elseif nahoda == 3 then
nastroj = ToolName3
elseif nahoda == 4 then
nastroj = ToolName4
elseif nahoda == 5 then
nastroj = ToolName5
elseif nahoda == 6 then
nastroj = ToolName6
elseif nahoda == 7 then
nastroj = ToolName7
elseif nahoda == 8 then
nastroj = ToolName8
elseif nahoda == 9 then
nastroj = ToolName9
elseif nahoda == 10 then
nastroj = ToolName10
elseif nahoda == 11 then
nastroj = ToolName11
elseif nahoda == 12 then
nastroj = ToolName12
elseif nahoda == 13 then
nastroj = ToolName13
elseif nahoda == 14 then
nastroj = ToolName14
elseif nahoda == 15 then
nastroj = ToolName15
elseif nahoda == 16 then
nastroj = ToolName16
end
--control generate number and variables
print(nahoda)
print(nastroj)
local Tool = Storage:FindFirstChild(nastroj)
if Tool then
Tool:clone().Parent = Backpack
end
end
-- hide giver and setup time
Part.ProximityPrompt.Enabled = false
Part.CanCollide = false
Part.Transparency = 1.0
Part.CanTouch = false
wait(math.random(Cas1, Cas2)) -- Cas is word czech language for time
Part.CanCollide = true
Part.Transparency = 0.0
Part.CanTouch = true
Part.ProximityPrompt.Enabled = true
end)
local Server = game:GetService("ServerStorage")
local Tools = Server.Tools
local Settings = script.Settings
local Prompt = script.Parent
local Part = Prompt.Parent
local ToolNames = {"AKM", "AR2", "Barret", "CM4A1", "Dixie", "FN-FAL", "Ithaca37"}
for i = 1, 9 do
table.insert(ToolNames, "Keycard Level "..i)
end
Prompt.Triggered:Connect(function(Player)
local Backpack = Player:WaitForChild("Backpack")
local Tool = Tools:FindFirstChild(ToolNames[math.random(#ToolNames)])
if Tool then
local ToolClone = Tool:Clone()
ToolClone.Parent = Backpack
end
Prompt.Enabled = false
Part.Transparency = 1
Part.CanCollide = false
Part.CanTouch = false
task.wait(math.random(Settings["Cas1"].Value, Settings["Cas2"].Value))
Prompt.Enabled = true
Part.Transparency = 0
Part.CanCollide = true
Part.CanTouch = true
end)
Hello, here’s a different version which will prevent duplicate tools from being awarded.
local Server = game:GetService("ServerStorage")
local Tools = Server.Tools
local Settings = script.Settings
local Prompt = script.Parent
local Part = Prompt.Parent
local ToolNames = {"AKM", "AR2", "Barret", "CM4A1", "Dixie", "FN-FAL", "Ithaca37"}
for i = 1, 9 do
table.insert(ToolNames, "Keycard Level "..i)
end
local function GiveRandomTool(Character, Backpack)
local Tool = Tools:FindFirstChild(ToolNames[math.random(#ToolNames)])
if Tool then
if Character:FindFirstChild(Tool.Name) then
GiveRandomTool(Character, Backpack)
else
local ToolClone = Tool:Clone()
ToolClone.Parent = Backpack
end
end
end
Prompt.Triggered:Connect(function(Player)
local Character = Player.Character
local Backpack = Player:WaitForChild("Backpack")
GiveRandomTool(Character, Backpack)
Prompt.Enabled = false
Part.Transparency = 1
Part.CanCollide = false
Part.CanTouch = false
task.wait(math.random(Settings["Cas1"].Value, Settings["Cas2"].Value))
Prompt.Enabled = true
Part.Transparency = 0
Part.CanCollide = true
Part.CanTouch = true
end)