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

Having Problems with StarterCharacterScripts in Filtering Enabled?

I currently have a script that when you press T on your keyboard, it shoots out a fire beam. It works perfectly fine as just a local script under StarterCharacterScripts but filtering enabled makes the beam invisible to others. I did some work and added a Remote Event under the local script in StarterCharacterScripts and added a regular script under it too. When I try the script in a server it says attempt to index global 'Player' (a nil value) under script but works fine in studio. I'm honestly just confused as freak...

LocalScript:

local en = true
Player = game.Players.LocalPlayer
char = Player.Character
mouse = Player:GetMouse()

game:GetService('UserInputService').InputBegan:Connect(function(input, process)
    if input.UserInputType == Enum.UserInputType.Keyboard and not process then
        if input.KeyCode == Enum.KeyCode.T then
	if en == false then return end
	en = false
script.RemoteEvent:FireServer(Player, input)

wait(0.5)
	en = true
end
end
	end)

Regular Script:

	local en = true
	Player = game.Players.LocalPlayer
	char = Player.Character
	mouse = Player:GetMouse()
	hum = char.Humanoid
	local cast = false
	
	script.Parent.RemoteEvent.OnServerEvent:connect(function(play,mousehit)
	game:GetService('UserInputService').InputBegan:Connect(function(input, process)
	    if input.UserInputType == Enum.UserInputType.Keyboard and not process then
	        if input.KeyCode == Enum.KeyCode.T and Player and Player.Character then
		if en == false then return end
		en = false
		local anim = hum:LoadAnimation(script["Animation"])
		anim:Play(0.1)
		anim:AdjustSpeed(0.9) .... etc. etc.

3 comments

0

Change :FireServer to :FireClient, also you need to change the on another script i know you have OnServerEvent:Connect(function(), change it to OnClientEvent:Connect(function()

0

^ i didn't test your code i just noticed that error, this error won't show in your Output because the Computer skips over the command if it's not fired with to the correct location.

0

isnt it supposed to fireserver since its in a local script? also it works now as fireserver so idk...

1 answer

✓ Accepted answer

###Of course you're getting an error. LocalPlayer is nil on the server, and GetMouse can only be called on the client. UserInputService is client side only as well. The other problem is line 11 of your LocalScript

script.RemoteEvent:FireServer(Player, input)

###You're passing an additional argument; the Player argument. The server already knows who fired the remote, so passing the player to FireServer is unnecessary.

###However, you do not need a RemoteEvent to play animations, as they are player physics and replicate to the server.

local en = true
local Player = game.Players.LocalPlayer
local char = Player.Character or Player.CharacterAdded:Wait()
local mouse = Player:GetMouse()

game:GetService('UserInputService').InputBegan:Connect(function(input, process)
    if input.KeyCode == Enum.KeyCode.T then
        if not en then return end -- == false irrelevant 
        
        local animation = char.Humanoid:LoadAnimation(script.Animation)
        animation:Play()
        -- do your other code
        en = false
        
        wait(0.5)
        en = true
    end
end)

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