When i try to launch my Code:
--// Services \\-- local ReplicatedStorage = game:GetService("ReplicatedStorage") local UserInputService = game:GetService("UserInputService") --// Variables \\-- local plr = game.Players.LocalPlayer local Char = plr.Character or plr.CharacterAdded:Wait() local Remote = ReplicatedStorage.FireBallEvent local Mouse = plr:GetMouse() --// Settings \\-- local Debounce = true local Key = 'Q' local Animation = Instance.new("Animation") Animation.AnimationId = 'rbxassetid://128853357' UserInputService.InputBegan:Connect(function(Input, IsTyping) if IsTyping then return end local KeyPressed = Input.KeyCode if KeyPressed == Enum.KeyCode[Key] and Debounce and Char then Debounce = false Remote:FireServer(Mouse.Hit) local LoadAnimation = Char.Humanoid:LoadAnimation(Animation) LoadAnimation:Play() wait(1) Debounce = true end end)
I Get alwas this Error:
sw.Mjanko25.Fireball:7: attempt to index local 'plr' (a nil value)
Can someone help me?
It's important that you understand the difference between the server and the client. Roblox uses the client-server model; when you play a game, your device, along with every other players', is a client. Every client is connected to a Roblox computer, known as the server, which manages the game and updates each client's world.
There are two distinct types of scripts in Roblox that operate either the client or the server:
LocalScript
s operate on the clientScript
s operate on the serverIt looks like your script should be LocalScript as it handles user input and attempts to get Players.LocalPlayer
which is only available on the client. After all, how could the server, which manages many different clients, assign the property properly? Your issue is, however, that you are not using a LocalScript; you are using a Script. Simply switch it out and your script should work as expected.
You can learn more about the client-server model here.