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

How can i make this Filtering Enabled with Remote Functions im Confused?

--Local Script
game:GetService("UserInputService").InputBegan:Connect(function(input, playar)
	if input.KeyCode == Enum.KeyCode.L then
		part = Instance.new("Part",workspace)
		part.Name = "Fireball"
		part.BrickColor = BrickColor.new("White")
		part.Transparency = 0.5
		player = game.Players.LocalPlayer
		character = player.Character
		Hum = character.Humanoid
		part.CFrame = character.UpperTorso.CFrame*CFrame.new(1,1,1)
		bv = Instance.new("BodyVelocity",part)
		bv.MaxForce = Vector3.new(1,1,1)
		bv.Velocity = Vector3.new(1,1,1)
		bv.P = Vector3.new(1,1,1)
		part.Shape = "Ball"
		part.Size = Vector3.new(1,1,1)
		part.CanCollide = false
		part.Material = "SmoothPlastic"
		if part.Touched then
			Hum:TakeDamage(69)
			
		
		end
		

		
	end <---- End is underlined in red for some reason idk how to fix
end)

REM = game.ReplicatedStorage:WaitForChild("RemoteEvent")
REM:FireServer(part)

---Server Script
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(playar,partspawn)
	
		part = Instance.new("Part",workspace)
		
		part.Name = "Fireball"
		
		part.BrickColor = BrickColor.new("White")
		
		part.Transparency = 0.5
		
		player = game.Players.LocalPlayer
		
		character = player.Character
		
		Hum = character.Humanoid
		
		part.CFrame = character.UpperTorso.CFrame*CFrame.new(1,1,-5)
		
		bv = Instance.new("BodyVelocity",part)
		
		bv.MaxForce = Vector3.new(1,1,1)
		
		bv.Velocity = Vector3.new(1,1,1)
		
		bv.P = Vector3.new(1,1,1)
		
		part.Shape = "Ball"
		
		part.Size = Vector3.new(1,1,1)
		
		part.CanCollide = false
		
		part.Material = "SmoothPlastic"
		
			
		end
		

		
	end
end)

1 answer

In your server sided script, the script attempts to retrieve the: LocalPlayer variable. However this is impossible to perform since the server doesn't have it's own player/localplayer.

---Server Script
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(playar,partspawn)

        part = Instance.new("Part",workspace)

        part.Name = "Fireball"

        part.BrickColor = BrickColor.new("White")

        part.Transparency = 0.5

        player = playar

        character = player.Character

        Hum = character.Humanoid

        part.CFrame = character.UpperTorso.CFrame*CFrame.new(1,1,-5)

        bv = Instance.new("BodyVelocity",part)

        bv.MaxForce = Vector3.new(1,1,1)

        bv.Velocity = Vector3.new(1,1,1)

        bv.P = Vector3.new(1,1,1)

        part.Shape = "Ball"

        part.Size = Vector3.new(1,1,1)

        part.CanCollide = false

        part.Material = "SmoothPlastic"


        end



    end
end)

Since every time when you call a remote function, the first argument is the player who called/fired the remote function/event.

Now all you'd need to do is optimize the script

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