Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

remote event script wont work one will but other wont no error how do i fix?

Asked by 6 years ago
01local plr = game.Players.LocalPlayer
02local InputService = game:GetService("UserInputService")
03 
04InputService.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
10end)
11 
12local plr = game.Players.LocalPlayer
13local InputService = game:GetService("UserInputService")
14 
15InputService.InputEnded:Connect(function(input)
16    local key = input.KeyCode
17    if key == Enum.KeyCode.R then
18       game.Workspace.fer:FireServer()
19    end
20end)

the script

01local fly = true
02game.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 
08i.Position = plr.UpperTorso.Position
09i.Anchored = true
10i.BrickColor = BrickColor.new("Dark blue")
11i.Shape = "Ball"
12i.Material = "Neon"
13i.Name = "Fire"
14i.CanCollide = false
15while fly == true do
View all 36 lines...
0
On line 6 of the local script you said "Checks if the key is Q" but the script is checking for R killer08932 149 — 6y

2 answers

Log in to vote
2
Answered by 6 years ago
Edited 6 years ago

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.

01local fly = true
02game.Workspace. act.OnServerEvent:Connect(function(L) -- Player object argument
03 
04    local plr = L.Character
05    local i = Instance.new("Part",plr)
06i.Position = plr.UpperTorso.Position
07i.Anchored = true
08i.BrickColor = BrickColor.new("Dark blue")
09i.Shape = "Ball"
10i.Material = "Neon"
11i.Name = "Fire"
12i.CanCollide = false
13while fly == true do
14    wait(.78)
15    i.Size = i.Size + Vector3.new(.4,.4,4)
View all 32 lines...
Ad
Log in to vote
0
Answered by
Pojoto 329 Moderation Voter
6 years ago

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:

1local 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.

01game.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 = Vector3.new(math.huge,math.huge,math.huge)
09    x.Anchored = false
10    b.Velocity = mouse.Hit.LookVector * 34
11wa.Parent = workspace
12 
13end)

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.

Answer this question