Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

local plr = game.Players.LocalPlayer
local InputService = game:GetService("UserInputService")

InputService.InputBegan:Connect(function(input)
    local key = input.KeyCode --Gets the key that the player pressed
    if key == Enum.KeyCode.R then --Checks if the key is Q
   game.Workspace.act:FireServer()

    end
end)

local plr = game.Players.LocalPlayer
local InputService = game:GetService("UserInputService")

InputService.InputEnded:Connect(function(input)
    local key = input.KeyCode 
    if key == Enum.KeyCode.R then
       game.Workspace.fer:FireServer()
    end
end)

the script

local fly = true
game.Workspace. act.OnServerEvent:Connect(function()
	local L = game.Players.LocalPlayer
	
	local plr = game.Players.LocalPlayer.Character
	local i = Instance.new("Part",plr)
	
i.Position = plr.UpperTorso.Position
i.Anchored = true
i.BrickColor = BrickColor.new("Dark blue")
i.Shape = "Ball"
i.Material = "Neon"
i.Name = "Fire"
i.CanCollide = false
while fly == true do
	wait(.78)
	i.Size = i.Size + Vector3.new(.4,.4,4) 
	
end
end)



game.Workspace.fer.OnServerEvent:Connect(function()
	local we = game.Players.LocalPlayer
	local plr = game.Players.LocalPlayer.Character
	local x = plr.Fire
	local wa = game.Players.LocalPlayer.Character:WaitForChild("Fire")
	local b = Instance.new("BodyVelocity",wa)
	local mouse = we:GetMouse()
	b.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
	x.Anchored = false
	b.Velocity = mouse.Hit.LookVector * 34
wa.Parent = workspace
	
end)

1 comment

0

On line 6 of the local script you said "Checks if the key is Q" but the script is checking for R

2 answers

✓ Accepted answer

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.

local fly = true
game.Workspace. act.OnServerEvent:Connect(function(L) -- Player object argument

    local plr = L.Character
    local i = Instance.new("Part",plr)
i.Position = plr.UpperTorso.Position
i.Anchored = true
i.BrickColor = BrickColor.new("Dark blue")
i.Shape = "Ball"
i.Material = "Neon"
i.Name = "Fire"
i.CanCollide = false
while fly == true do
    wait(.78)
    i.Size = i.Size + Vector3.new(.4,.4,4) 

end
end)



game.Workspace.fer.OnServerEvent:Connect(function(we,mouse) -- Player object argument you would need a second argument for the mouse also
    local plr = we.Character
    local x = plr.Fire
    local wa = x:WaitForChild("Fire")
    local b = Instance.new("BodyVelocity",wa)
    b.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
    x.Anchored = false
    b.Velocity = mouse.Hit.LookVector * 34
wa.Parent = workspace

end)

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:

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.

game.Workspace.fer.OnServerEvent:Connect(function(player)
    
    local plr = player.Character
    local x = plr.Fire
    local wa = plr:WaitForChild("Fire")
    local b = Instance.new("BodyVelocity",wa)
    local mouse = we:GetMouse()
    b.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
    x.Anchored = false
    b.Velocity = mouse.Hit.LookVector * 34
wa.Parent = workspace

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.