local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() Mouse.KeyDown:connect(function(Key) Key = Key:lower() if Key == "z" then print ("Test") local fire = Instance.new('Fire') end end)
I'm new to scripting and was wondering how to put the fire onto the player's left arm. What I am trying to do is make it so if the player has pressed the "z" key, their left arm will set on fire. The script above is what I have so far. Whenever I try and do it, the script breaks and in the output it says "Player is not a valid member of humanoid".
I don't think that the error you are getting is part of the script above as you do not access the humanoid in the characters model.
We now have a whole service to manage the users input called UserInputService which is why KeyDown and KeyUp deprecated so please do not use them.
As you have posted a script I will give an example, this also uses a remote event as you should have FilteringEnabled:-
Server script:-
-- add the event (You do not need to create this in a script, you can manually add it) local remoteFire = Instance.new('RemoteEvent', game:GetService('ReplicatedStorage')) -- create a remote event object and adds it to the rep storage so both the server and client can see it remoteFire.Name = 'remoteFire' remoteFire.OnServerEvent:connect(function(plr, fire) -- the 1st arg is passed automatically followed by all of the other args send by the client local char = plr.Character -- the character is the model in the workspace this could be nil if char then -- check for a nil character -- we could also check that the player does not have the fire else we could be adding more? you can look into this -- fire is a boolean passed to determine if we add or delete the fire if fire then -- add fire if char['Left Arm'] then local fire = Instance.new('Fire', char['Left Arm']) -- set other things for the fire ect print('Fire added') else print('Character model does not have a left arm') end else -- remove fire, this should be simple to add end else print('Character model is nil') end end)
This is a local script in StarterPlayerScripts:-
local usrInpServ = game:GetService('UserInputService') -- this can only be used in a local script the server does not have any access to the clients inputs local remoteFire = game:GetService('ReplicatedStorage'):WaitForChild('remoteFire') -- the name of the event we created on the server side local deb = true usrInpServ.InputBegan:connect(function(inputObj, gameProcEvent) if deb then -- this will help with stopping events are we do not want to spam the remote -- it is good practice to use "Enums" instead of values or ints if inputObj.UserInputType == Enum.UserInputType.Keyboard then -- only run with keyboard if inputObj.KeyCode == Enum.KeyCode.Z then deb = false -- we now can process so stop other requests remoteFire:FireServer(true) -- we do not pass the player as the server knows what player fired the event -- i dont know how you want to handle multiple requests -- atm this will only run once -- we could add a cool down wait(10) deb = true end end end end)
I hope this helps, please comment if you do not understand how/why this script works.
local rightArm = Player.Character["Right Arm"] local leftArm = Player.Character["Left Arm"] local fire = Instance.new("Fire") fire.Parent = rightArm fire.Parent = leftArm
This will put the fire in the arm :)