Remote events. why

Please format your scripts using this button:

30%20PM

4 Likes

You haven’t given very much information so I’m going off based on what you’ve provided us with.

Have you tried using print statements to see if the local script is sending and the server script is receiving? I also see you have a function in the local script called CreateDamageText, is it possible that an error has occurred in that function that prevents the local script from continuing on to fire the server event? The only advice I can give you here is take advantage of print statements. Put them everywhere and take note of which ones don’t show up so that you can find the root of your problem.

I already have print() in both scripts, and the CreateDamageText function works fine, besides the print is after the CreateDamageText function and it still prints "fired", so nothing wrong with that.

Only the localscript actually prints by the way, and i’ve tried having a touched() script in the script and for some reason it didnt work

You said that nothing happens at all when you test it out, in my experience when people say nothing happens they mean there are no print statements or error messages whatsoever and nothing changes at all.

So if the “fired” print statement goes off in the local script just fine while the server print statement does not, I can think of many possibilities as to why. The one I’m leaning towards is your hitev variable in the local script may be referencing the wrong remote event, though I can’t see what you’ve set the variable as so this is just a guess from my lack of knowledge on the situation.

What is “enemhum?” You haven’t really specified what that part of the script is, but based on your code it seems to be either a character or a humanoid. I’ve had my experience with remote events in the past and the biggest issues I ran into were passing the wrong types of arguments. Maybe the issue stems from the arguments you’re passing; I’ve had situations where my remote events wouldn’t work and all I had to do was change the way I was passing my arguments and it worked just fine.

okay, enemhum is hit.Parent:FindFirstChildWhichIsA("Humanoid"), the touched script is in the LocalScript

and both scripts use hitev = game.ReplicatedStorage.Hit
image

And i’ve read the RemoteEvent wiki page and interpreted it to the best of my understanding at got little to nothing about the argument perimeters.

Just a heads up, doing it like this is gonna get your game exploited in the first 2 minutes of it being released.

Here, you are making the localscript tell the server who to hurt and how much to hurt them. If I were an exploiter and I wanted to, I could automatically loop through all of the players in the game and kill them like this:

for _, player in game.Players:GetPlayers() do
    hitev:FireServer(100, player.Character.Humanoid) -- TELLING the server who to hurt and by how much
end

Instead, the player should only ever fire the remote and say who it thinks the bullet hit. The server must then make sure that that player is within a certain range, both players have line of sight, etc. THE CLIENT SHOULD NEVER TELL THE SERVER WHAT TO DO - that’s the jist of it.

I highly recommend you read this short topic about game security - you’ll thank me in the long run :joy: How you should secure your game - A beginner guide for secure networking and developing anticheats

I know this doesn’t really answer the OP but it is really important.

4 Likes

Thanks, but all of that wouldn’t be a problem if i knew why the heck the Touched() function doesnt work inside of a script when i try it.

If hitev is referencing an event that is inside replicated storage, you’re doing it wrong. You’re gonna wanna put that event somewhere in the workspace if you want the client to communicate with the server. Remote events that are in replicated storage are for if you want the server to communicate with the client.

oh. well i sure am stupid. Thanks for the insight, ill go see what happens

Okay, so i put the RemoteEvent inside of the Tool and made both scripts reference it as hitev = script.Parent.Hit buuuuuut nothing changed.

No problem, remote events are some of the most confusing things ever in my opinion. Let us know how it goes!

The fact is, if you are using it right now, even if its broken for the normal script, an exploiter can still use the remote event!

Read the tread I put, it’s really informative and will help you lots. Its far better to sort this out now and keep it sorted than to do it in the future when theres already a lot of exploits for you game because you didn’t do it earlier. Once you do it enough, it becomes second nature!

Okay, so i put the RemoteEvent inside of the Tool and made both scripts reference it as hitev = script.Parent.Hit buuuuuut nothing changed.

The way I would go about it is have one remote event in the workspace under a script for remote events to be received by the client and have another one in replicatedstorage for communication from the server to the client and have a local script receive events from anywhere in the client, you can keep the local script inside of the child of a tool. Here is a list of where local scripts can be put if you want them to run.

I would never put a remote event inside of a tool, to be honest. Doing it the way I described above has never caused any problems for me.

I might be wrong, but it seems as if you’re trying to have both scripts reference one remote event. You cannot do that; you must have one in the workspace to receive requests from the client and one for every client to receive requests from the server.

Okay i didnt really understand what you just said, but here is the tool yool
i tried moving the RemoteEvent into both ReplicatedFirst and the Workspace and made the scripts reference them accordingly to no avail

Okay so I decided to whip up this little place on studio so you can get a better understanding of how best to create a remote event environment in a game. It’s not very pretty but basically, you’ll have a button that sends a request to the server to create a part, and then the server will send a request to the client to tell them the part has been removed 5 seconds later. This place should provide a good understanding of how this all works.

Here is the download if you’d like to check it out, try to study the scripts, they’re very quick and to the point, no more than 25 lines combined.RemoteEventTutorial.rbxl (18.0 KB)

ok so im an idiot and i figured it out on my own. Thanks for your help.

Care to share the solution so others may benefit from your new found knowledge?

7 Likes

As @RamJoT pointed out, it’s courteous to mark a post with what you did to solve the problem as the solution rather than a post that just says “I found a solution”.

So basically i scrapped everything and made a new script in workspace with the following code:

game.ReplicatedStorage.Hit.OnServerEvent:Connect(function(play, damage, human) human.Health = human.Health - damage print("it actually worked, and now " .. human.Parent.Name .. " took " .. damage .. " damage.") end)

and put the event into replicated storage and had all the localscripts just do all the work then run

hitev:FireServer(dmg, enemhum)

hitev is the event in replicatedstorage, dmg is the damage dealt, and enemhum is the humanoid to deal the damage on, yes i know its easily exploitable, ill find another way around that.

1 Like

There is a very in-depth tutorial on RemoteEvents (By ScriptGuider) if you need extra help!
https://www.youtube.com/watch?v=4Dc_bri9mjs @dogefan91