Getting error while going through the tutorial “Hit Detection with Lasers”

Hi,

I hope someone can help me. I’ve been going through all the tutorials on the Learn Roblox Studio site (Learn Roblox). I’m currently going through the tutorial “Hit Detection with Lasers”. I finished inputting the code shown on the page “Firing Towards the Target”. After entering all the code on that page, I then tested. When I fire the laser, I get the below error.

15:00:00.187 Players.Player1.Backpack.Blaster.ToolController:44: attempt to index nil with ‘Character’ - Server - ToolController:44
15:00:00.188 Stack Begin - Studio
15:00:00.189 Script ‘Players.Player1.Backpack.Blaster.ToolController’, Line 44 - function fireWeapon - Studio - ToolController:44
15:00:00.190 Script ‘Players.Player1.Backpack.Blaster.ToolController’, Line 79 - function toolActivated - Studio - ToolController:79
15:00:00.191 Stack End - Studio

This error is generated by the below line of code.

weaponRaycastParams.FilterDescendantsInstances = {Players.LocalPlayer.Character}

Here’s a screen shot from Roblox Studio. I even tried copying and pasting the code from the tutorial, but I still get the error. Clearly, I’m doing something wrong. Anyone else have this problem with the tutorial? Any help would be appreciated

Here’s a screen shot of the relevant code from the tutorial (Firing Towards the Target)

Thanks,
Leif_aw

1 Like

Change it to a LocalScript and it should work fine my good friend!

2 Likes

<< Change it to a LocalScript and it should work fine my good friend!>>

(slaps hand to forehead)

Thank you so much Jackscarlett! That did the trick. What a clumsy error on my part. Thanks for taking the time to help. Much appreciated.

Leif_aw

1 Like

Just wanted to let you know local scripts can be edited by exploiters with ease and FE exists so the damaging and raycasting wont show up to other players, only the player who fired it.

HI Neotrinax,

“and FE exists so the damaging and raycasting wont show up to other players”

As I’m still learning Roblox, I apologize if this is a dumb question. What do you mean by “FE”?

Thanks,
Leif_aw

It is not actually I did a horrible job with explanation in that post, by FE I mean filtering enabled. Filtering enabled is there to prevent changes in the client to replicate to other clients or the server but with some exceptions like animations. Another reason it exists is to help fight exploiters from just changing something in their client (lets say delete the base plate) to replicate or happen to other players screens. Take a look at this article, Client-Server Model | Roblox Creator Documentation. For now don’t worry about this until you want to start making games for other players.

Thank you so much for the explanation and the helpful link!

Leif_aw

1 Like