i want the npc to say “Kill butter5432m for 15 coins” using my name as an example
script:
local players = game:GetService("Players"):GetPlayers()
local picked = players[math.random(1, #players)]
local plr = game.Players.PlayerAdded:Connect(function(plr)
local char = plr.Character or plr.CharacterAdded:Wait(1)
local hum = char:WaitForChild("Humanoid")
local rep = game:GetService("ReplicatedStorage")
local rem = rep:WaitForChild('RemoteEvent')
local chat = game:GetService("Chat")
local mouse = script.Parent
local debounce = false
mouse.MouseClick:Connect(function()
if debounce == false then
debounce = true
wait(0.1)
chat:Chat(script.Parent.Parent.Head,"Kill"picked.Name,"White")
rem:FireClient(plr)
print("working")
wait(30)
debounce = false
end
end)
end)
the script is inside a clickdetector inside an npc
local players = game:GetService("Players"):GetPlayers()
local picked = players[math.random(1, #players)]
local plr = game.Players.PlayerAdded:Connect(function(plr)
local char = plr.Character or plr.CharacterAdded:Wait(1)
local hum = char:WaitForChild("Humanoid")
local rep = game:GetService("ReplicatedStorage")
local rem = rep:WaitForChild('RemoteEvent')
local chat = game:GetService("Chat")
local mouse = script.Parent
local debounce = false
mouse.MouseClick:Connect(function()
if debounce == false then
debounce = true
wait(0.1)
chat:Chat(script.Parent.Parent.Head, "Kill "..picked.Name, "White")
rem:FireClient(plr)
print("working")
wait(30)
debounce = false
end
end)
end)
output message:
Workspace.Dummy.ClickDetector.Script:2: invalid argument #2 to 'random' (interval is empty)
the script is located in a clickdetector in the dummy
normal script*
local plr = game.Players.PlayerAdded:Connect(function(plr)
local char = plr.Character or plr.CharacterAdded:Wait(1)
local hum = char:WaitForChild("Humanoid")
local rep = game:GetService("ReplicatedStorage")
local rem = rep:WaitForChild('RemoteEvent')
local chat = game:GetService("Chat")
local mouse = script.Parent
local debounce = false
mouse.MouseClick:Connect(function()
local players = game:GetService("Players"):GetPlayers()
local picked = players[math.random(1, #players)]
if debounce == false then
debounce = true
wait(0.1)
chat:Chat(script.Parent.Parent.Head, "Kill "..players[picked].Name, "White")
rem:FireClient(plr)
print("working")
wait(30)
debounce = false
end
end)
end)
output error:
Workspace.Dummy.ClickDetector.Script:19: attempt to index nil with 'Name'
kill (the random player chosen ) for 15 coins?
and then after it say that a gui pop up and when u press ok the npc will say ok also in chat form
i already have the gui ready