I'm kinda abusing the idea of filteringenabled right now, basically, I want to disable this script for only the client and not the whole server.
Here's my script;
1 | script.Parent.Touched:connect( function (hit) |
2 | player = game.Players:GetPlayerFromCharacter(hit.Parent) |
3 | if player and player:IsA( "Player" ) then |
4 | player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 1 |
5 | script.Disabled = true |
6 | end |
7 | end ) |
I also tried;
1 | player = game.Players.LocalPlayer |
2 |
3 | script.Parent.Touched:connect( function (hit) |
4 | if player and player:IsA( "Player" ) then |
5 | player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 1 |
6 | script.Disabled = true |
7 | end |
8 | end ) |
Neither of them works.
(keep in mind that this is a localscript, i tried using normalscript for this script and it worked fine. I just want to replicate the changes to only the client, not the whole server.)
Local scripts only run when they are a descendant of something that is individual to the player, such as their gui, character, backpack, etc. As a result, a local script that is inside of a part will not run.
To fix this, you can put the local script inside one of these things that are individual to the client, and do something like this:
1 | workspace [ "PartName" ] .Touched:Connect( function (hit) |
2 | if hit.Parent = = game.Players.LocalPlayer.Character then |
3 | --do stuff |
4 | end |
5 | end ) |
However, if you only edit the leaderstats with a local script, it will not update on the server, thus not updating their stat for everyone else. To fix this you can use a server script instead and keep track of all the players who have touched the part before, only letting them touch it once.
01 | local plrsWhoTouched = { } |
02 | script.Parent.Touched:Connect( function (hit) |
03 | local plr = game.Players:GetPlayerFromCharacter(hit.Parent) |
04 | if plr then |
05 | for _,v in pairs (plrsWhoTouched) do |
06 | if v = = plr then return end |
07 | end |
08 | plr.leaderstats.Stage.Value = plr.leaderstats.Stage.Value + 1 |
09 | table.insert(plrsWhoTouched, 1 ,plr) |
10 | end |
11 | end ) |