01 | local plr = game.Players.LocalPlayer |
02 | local InputService = game:GetService( "UserInputService" ) |
03 |
04 | InputService.InputBegan:Connect( function (input) |
05 | local key = input.KeyCode --Gets the key that the player pressed |
06 | if key = = Enum.KeyCode.R then --Checks if the key is Q |
07 | game.Workspace.act:FireServer() |
08 |
09 | end |
10 | end ) |
11 |
12 | local plr = game.Players.LocalPlayer |
13 | local InputService = game:GetService( "UserInputService" ) |
14 |
15 | InputService.InputEnded:Connect( function (input) |
16 | local key = input.KeyCode |
17 | if key = = Enum.KeyCode.R then |
18 | game.Workspace.fer:FireServer() |
19 | end |
20 | end ) |
the script
01 | local fly = true |
02 | game.Workspace. act.OnServerEvent:Connect( function () |
03 | local L = game.Players.LocalPlayer |
04 |
05 | local plr = game.Players.LocalPlayer.Character |
06 | local i = Instance.new( "Part" ,plr) |
07 |
08 | i.Position = plr.UpperTorso.Position |
09 | i.Anchored = true |
10 | i.BrickColor = BrickColor.new( "Dark blue" ) |
11 | i.Shape = "Ball" |
12 | i.Material = "Neon" |
13 | i.Name = "Fire" |
14 | i.CanCollide = false |
15 | while fly = = true do |
It seems like you didn't know there was an argument in FireServer that is the player object. You can't use game.Players.LocalPlayer in a server script because it is for the server not a client.
01 | local fly = true |
02 | game.Workspace. act.OnServerEvent:Connect( function (L) -- Player object argument |
03 |
04 | local plr = L.Character |
05 | local i = Instance.new( "Part" ,plr) |
06 | i.Position = plr.UpperTorso.Position |
07 | i.Anchored = true |
08 | i.BrickColor = BrickColor.new( "Dark blue" ) |
09 | i.Shape = "Ball" |
10 | i.Material = "Neon" |
11 | i.Name = "Fire" |
12 | i.CanCollide = false |
13 | while fly = = true do |
14 | wait(. 78 ) |
15 | i.Size = i.Size + Vector 3. new(. 4 ,. 4 , 4 ) |
Whenever you use OnServerEvent:Connect(function()
, always put player
in the parentheses of the function. player
will be a variable that stores the player who fired the server event. Now you don't need to write:
1 | local we = game.Players.LocalPlayer |
You already have a player variable to be accessed. Also, LocalPlayer
doesn't work on server scripts because the server has no idea who the LocalPlayer
is; it only works on local scripts.
01 | game.Workspace.fer.OnServerEvent:Connect( function (player) |
02 |
03 | local plr = player.Character |
04 | local x = plr.Fire |
05 | local wa = plr:WaitForChild( "Fire" ) |
06 | local b = Instance.new( "BodyVelocity" ,wa) |
07 | local mouse = we:GetMouse() |
08 | b.MaxForce = Vector 3. new( math.huge , math.huge , math.huge ) |
09 | x.Anchored = false |
10 | b.Velocity = mouse.Hit.LookVector * 34 |
11 | wa.Parent = workspace |
12 |
13 | end ) |
However, your script still has tons of errors, and I suggest doing more research on what the server and player can access and what they can not access. The mouse
can't be accessed on a server script, that doesn't make any sense.