A few things wrong here.
1: Player character
When using local scripts, or any script at all that's running as soon as the client has registered in the game, it's wise to 'wait' for the character to load, before trying to index it. We can do this by attaching the wait function, to the 'CharacterAdded' event of the player, and have a variable to store the result. Like this:
local Player = game.Players.LocalPlayer
local Char = Player.CharacterAdded:wait()
Now, obviously this won't be the case for every situation. Sometimes the character loads on time, and the CharacterAdded event is redundant. But since there's no guarantee, we can use an 'or' statement to settle the dispute:
local Player = game.Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:wait()
2: Your function
Nothing seems to be wrong with the code in your function, however there's one simple thing you forgot to do; which is binding it to a mouse event. The mouse event you're most likely looking for us 'KeyDown', which fires whenever a key is pressed on your keyboard (obviously). All you have to do is use the 'connect' method with this event, and return your function as an argument. Finally, this is what the final result should look like:
local Player = game.Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:wait()
local Torso = Char:WaitForChild("Torso")
local Mouse = Player:GetMouse()
local function EarthKick(key)
key = key:lower()
if key == "v" then
for i = 1, 100, 3 do
local EarthBlock = Instance.new("Part")
EarthBlock.Parent = workspace
EarthBlock.Size = Vector3.new(math.random(4, 6),math.random(4, 6),math.random(4, 6))
EarthBlock.Anchored = true
EarthBlock.TopSurface = 0
EarthBlock.BottomSurface = 0
EarthBlock.BrickColor = BrickColor.new("Brown")
EarthBlock.CFrame = CFrame.new(Torso.Position.x,5,Torso.Position.z) * CFrame.new(0,0,-1) * CFrame.Angles(math.random(),math.random(),math.random())
end
end
end
Mouse.KeyDown:connect(EarthKick)
Hope this helped.
2 comments
Is this your whole script? If not, please give the whole script so we can help.
Its the whole script