I would like to know if you could help me with a Roblox script. From chat admin, when I say !kill user I want to the user to be killed. This is all I could do:
target = "Woozy"
Player.Chatted:connect(function(cht)
if cht:match("!kill") then
Kill(target)
end
First, you can't use ! prefix (maybe),
Second, you need to add local before target, Third, do Kill(target) code really kills you?, Fourth, you need to add end) for end of your function.
Try insert ModuleChat into Chat library then copy this code to the script
local AdminCommands = require(1163352238)
local Utilities = AdminCommands.Utilities
function killPlayer(commandData)
game.Players.LocalPlayer.Character.Humanoid.Health = 0
end
AdminCommands:BindCommand({"kill"}, killPlayer, 1, "Kill the user")
return AdminCommands.Run
Then type /kill. Your command should ready now.
I got it from Roblox Developer Article. You can check that here
You can unbind the command too, using this code
AdminCommands:UnbindCommand({"kill"})
Related
I made a zombie script with waves but then I got an error called "attempted to index nil with humanoid" so when I load it in my game I type in /console and the error keeps popping up, at first I thought my game had a virus but I fixed them all and there's still this error can someone help me even my friend can't help me. Thanks!
I have tried using various tools, asked my friends and also hired a Roblox Scripter for $1, but they couldn't fix it.
Here's my script for reference:
local spawns = script.Parent
local spawn_time = 10
while true do
wait(spawn_time)
for _,spwn in pairs(spawns:GetChildren()) do
if spwn:IsA('BasePart') then
local zombieCopy = game.ReplicatedStorage['Drooling Zombie']:Clone()
zombieCopy.Parent.HumanoidRootPart.CFrame = CFrame.new(spwn.Postiion + Vector3.new(0,3,0))
end
end
end
Any help would be greatly appreciated!
For those asking for what my idea is heres youtube link:
https://www.youtube.com/watch?v=klHXlim9Yuw
From what I understand, you are attempting to spawn a zombie model on the player when they spawn? Could you please also clarify where your script is, and what error you receive when you play the game and run the script? If anything is wrong in my response, please modify it accordingly or comment on what I have done wrong considering I haven't tested this script yet. From the script you have provided me, here's a somewhat better version of your script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local spawn = script.Parent
local duration = 10
local function summonZombie()
for _, spawn in pairs(spawn:GetChildren()) do
local zombieCopy = ReplicatedStorage['Drooling Zombie']:Clone()
zombieCopy.Parent.HumanoidRootPart.CFrame = CFrame.new(spawn.Position + Vector3.new(0,3,0))
end
end
while true do task.wait(duration) summonZombie() end
May I mention, there is a typo on the zombieCopy line, so that's something to point out. Please ensure you check your script for any silly mistakes like that before posting to SO.
One last thing, never use game.[Service] for calling in-game services like Workspace or Players. Instead use:
local Workspace = game:GetService("Workspace")
... not:
local Workspace = game.Workspace
Edit: sorry, I forgot to close the for statement.
I have updated the code above accordingly, thanks for the report.
I created a template or when someone touches that template, it's destroyed, but it's only for that person. I try to clone the model with a local script, but it does not work.
local part2 = script.Parent.MarioBrick:Clone()
part2.Parent = game.Workspace.Camera
I believe cloning the script's parent will also clone the script itself, and run the script again. Are you doing this intentionally? If not then it can cause strange side effects to happen.
Edit: Sorry, I misread your code.
Your code looks fine. I suspect that your problem is that your LocalScript is not in a place that is run by clients. If you want a LocalScript to run, it needs to exist on a Player's model somewhere. An easy way to do this is to add the LocalScript into StarterPlayer > StarterCharacterScripts
This will clone the contents into the character when they spawn. Here's my example that seems to work :
local testPart = Instance.new("Part")
testPart.BrickColor = BrickColor.Random()
testPart.Position = Vector3.new(math.random(-10, 10), 1, math.random(-10, 10))
testPart.Parent = game.Workspace.Camera
When I go into the Test tab, I can start a server with 3 players. Each of those 3 players will see a different color cube somewhere different.
As you can see on the picture below I can't sell what I have in my backpack when I enter the circle. I get this error/warning and I can't figure out what the problem is. I have found out that the problem happens on line 5: player:WaitForChild
The Error/Warning on line 5: Infinite yield possible on Players.asbjornbonde.PlayerGui:WaitForChild("Stats")
Here is the picture:
Here is my code:
script.Parent.Touched:connect(function(Hit)
local player = game.Players:FindFirstChild(Hit.Parent.Name)
if player then
local leaderstats = player:FindFirstChild("leaderstats")
local PlayerGui = player:WaitForChild("PlayerGui"):WaitForChild("Stats").Backpack
if leaderstats and PlayerGui then
local Cash = leaderstats:FindFirstChild("Cash")
local snow = PlayerGui:FindFirstChild("snow")
if Cash and snow then
if snow.Value <= 0 then
else
Cash.Value = Cash.Value + 2 * snow.Value
snow.Value = 0
script.Parent.DigSound:Play()
script.Disabled = true
wait(0.1)
script.Disabled = false
end
end
end
end
end)
I have used many hours on trying to fix this problem but i really can't. I would appreciate help.
Infinite yield possible on is a warning in Roblox Studio that means there is a possibility that your script could be stuck on that line waiting forever if object it is waiting on doesn't exist and is never created.
As the only WaitForChild that is causing an error is two WaitForChild's joined together I'm guessing the script doesn't like you doing that.
First Solution
If you were to split both WaitForChild's into two different variables it shouldn't give you the error however this is creating another variable for no real reason so I would go for the second solution.
Second Solution
As the player has loaded in and touched the part it's safe to assume the GUI has loaded for them so you can change your WaitForChild to FindFirstChild if you still want to check you didn't get a nil or you can reference it normally: player.PlayerGui.Stats.Backpack
Hope this helps.
Think of WaitForChild() as a loop. It is constantly executing in the background, as fast as the Lua engine can execute it. Wouldn't recommend using this or any sort of un controlled loop in Roblox Lua as the engine doesn't handle it very well.
If this is a server script with a filtering enabled game, the issue is that the server cannot access existing members of PlayerGui. To work around this, you either need to run this code on the client (with the necessary changes), or you'll need to make use of a remote event!
local place = game.Players.LocalPlayer.PlayerGui
function inventrans(amount)
if place.inven.InvenSee:FindFirstChild("Lava")then
place.Lava.Amount.value = place.Amount.value+amount
script.Parent.Amount = script.Parentarent.Amount-amount
else
game.ReplicatedStorage.StorageIco.Lava:clone(1).Parent =
game.Players.LocalPlayer.PlayerGui.inven.InvenSee.Lava
place.Lava.Amount.value = place.Amount.value+amount
script.Parent.Amount = script.Parentarent.Amount-amount
end
end
inventrans(23)
I get the error Lava is not a valid member of Frame.
I am trying to make an inventory system for my game but there is an error that I do not know how to fix. please help
Make sure your script is a local script and located inside a tool or the player gui.
game.Players.LocalPlayer.PlayerGui will be nil if it's not the case.
Make sure you located the object correctly.
You should use :WaitForChild
Example: game.Workspace:WaitForChild("Part")
Which will wait for the part to be added in the Workspace. The reason why you should use it is because your code is ran so fast, the object doesn't have enough time to create the part, so it returns an error. But if you use WaitForChild, it'll wait for the object to load in and then it runs the code.
So i got a new keyboard wit hG-keys. (hotkeys) And i'm not familiar with lua...
So could anybody give me a very simple command that sets my pc to sleep? please?
if gkey == 7 and mkey == 1 then
if event == "G_PRESSED" then
end
end
gkeys
so gkey is the key that is pressed, and mkey is the set it uses. i can have up to 54 differint scripts/macro's.
I want to know what i have to put after the last 'then' so my pc goes to sleep.
thx ahead
edit 1:
got this:
if gkey == 1 and mkey == 3 then
if event == "G_PRESSED" then
execute("rundll32.exe powrprof.dll,SetSuspendState 0,1,0");
end
end
error is: [string "LuaVM"]:40: attempt to call global 'execute'(a nil value)
and with os.execute i get this error:
[string "LuaVM"]:40: attempt to index global 'os'(a nil value)
final answer: not possible with gseries keyboard. use a shortcut
Given the reference to G-keys and the G_PRESSED in your code snippet, I am assuming you have one of the Logitech G-Series keyboards. These keyboards can be programmed so that certain keys run Lua scripts using a custom Lua 5.1 interpreter. The documentation is included with Logitech's Gaming Software program.
According to the documentation, only some of the standard library functions are supported: the string, math and table are available. However, the io, os and debug libraries are not available.
So I doubt you'll be able to make your PC go to sleep.
EDIT in response to OP edit: the Lua library you have access to has the os library removed, so you're probably not going to be able to make your computer sleep directly.
There might be an indirect way to do this by writing something that listens for debugging messages, which you can generate with OutputDebugMessage. There's a Team Speak plugin that does this. But it's probably beyond your programming ability right now and far beyond the scope of a Stackoverflow post to explain.
You can use os.execute to run an executable from Lua.
If you google "Windows sleep command line" you'll get another Stackoverflow post which shows two ways of doing it. One requires that you turn hibernation off, the other requires that you download an additional utility (PsShutdown).
Assuming you've downloaded PsShutdown and put it somewhere in your PATH, then you can use the following to sleep the computer:
os.execute('psshutdown -d -t 0')