tried this out and the event is still firing for all players
we need to see your entire code
local script – ---------------------------- Variables ----------------------------local up1 = - Pastebin.com
script – ---------------------- Multipliers -------------------------script.upgrade.OnS - Pastebin.com
If you have your local script with all your touch listeners in each player, if just one player touches a part, the listener will fire on all players since each player has a touch listener on the part
OnTouched events can work in both server and local scripts but I suppose it’s much easier on server script for most parts instead of sending events to a server script
from a local script where you can already use a server script
for it.
--This is a server script
local up1 = game.Workspace.examplepart
local function onTouched(hit)
print(hit.Parent.Name.."touched")
local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if plr.leaderstats.Money.Value >= 100 then
print('you got enough money')
player.leaderstats.Money.Value = player.leaderstats.Money.Value - 100
player.leaderstats.Multiplier.Value = player.leaderstats.Multiplier.Value + 1*(player.leaderstats.Rebirth.Value + 1)
else
print('too poor!')
end
end
up1.Touched:connect(onTouched)
[Edited]
where would i move the local script from starter player scripts to ?
[Workspace.Events:9: attempt to index local ‘plr’ (a nil value)]
i get that error when i try this
I have edited it, maybe it’ll work now…
In each touch listener, check if the player is actually the one that touched the part
Something like this:
function onTouched(hit)
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if player ~= nil and player == game:GetService("Players").LocalPlayer then
--fire remote event
end
end
--add touch listener here
An alternative would be to move all your touch listeners into one server script like what @Dev_0V did
Just a thought. If you just want this to work, is it necessary to FireServer for you achieve what you’re trying to do? You could do all this in a server script if you wanted. Or is it because you want to get remote events to work for the sake of learning it?
If you are still completely unsure, you might wanna check out the following articles;
https://developer.roblox.com/en-us/api-reference/class/RemoteEvent/index.html
half want to learn remote events but at this point ill use a single server script if i can get it working but the one Dev_0v posted isnt working for me
ive already looked at both those articles and they didnt help
it’s not working because I just realized I have not specified the player correctly as @downcrusher69 did
What @downcrusher69 is saying is, since you have a Touched event for a part, in every single player, this Touched event will fire regardless of who touches it, since every player has a Touched event connected to the same part. So basically, the way you’ve set it up, it doesn’t matter who touches the button. Anybody who touches the button will have their Touched function fired and so will everybody else in the game.
What I would personally do is just move everything to a server script and have the server control the Touched. It seems like you understand how remote events works anyway, so you’re good on that part. Having the client determine the Touched is highly exploitable to begin with, and an exploiter could FireServer() constantly and abuse it
finally got it working moving it all into a server script worked out thanks a ton you guys have been a really good support <3
Glad it worked out bro! Keep up the grind and develop great stuff. Never stop learning