How can i make a pvp disabler?

I created a bool value inside the player that when set to off, the player is supposed to be taking no damage,
Screenshot 2025-09-23 210743

but when i tried this script, the player kept getting damaged by the other player even though the damaged player has their boolvalue set to false (the “immune!” print is supposed to come out if they are not being damaged but instead the (“damaged!”) print is coming out instead, is there anything wrong with the script?

My best guess is that you are setting the value of pvp enabled to false by a local script, but doing it that way will only set it to false for that clients computer, not the server or other clients.

If that’s not the problem though the second most likely issue I think is you probably have some system overwriting it back to true that you aren’t realizing is triggering.

I am using a button made by the local script to turn the boolvalue on and off, would that be the reason why the player can still damage the other player?

You are changing the value of the boolValue on the client, that does not replicate to the server but the desired client itself

1 Like

Local Scripts are called “Local”, because they only run on your device. Which means, if someone turns off PVP only on their screen, and not making the server do it, they’ll still get damaged; everyone else’s machines think PVP is Enabled.
If you want to make it so that it’s disabled, just fire a RemoteEvent (easier solution) which makes the bool enabled, or invoke a RemoteFunction (might be a tad bit harder to learn)

Yes. Changes made locally are not replicated to server. You would instead need to have the button trigger a remote event and then change it on sever script when event fires.

Basically, instead of

pvp.Value = true

you’d want to do

setPvpEnabledEvent:FireServer(true)

and then on the server when it receives this event, it should validate that the player can currently set their pvp preference (e.g. they are not in combat, they can set it)

Make a wrapper function for taking damage instead of taking it dirrectly.

Yeah, changes you make with a local script don’t change things in the server (there are technically exceptions but they don’t apply here). So the local script runs on my computer and changes the value to true, but the server is who is actually in charge of that and so the server doesn’t see it was changed. You have to make the server change it instead. Basically you just need to send whether it’s enabled or not through a remote event so the server knows when the client wants to turn it on/off.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.