Error Server Script!

–this is my script to get through a door when you get a certain amount of cash but, when someone buys it, it buys for the whole server. I’ve tried putting it in a local script but it just doesn’t work. Can someone please tell me how I can fire for only one client

local rc = 2500

local debounce = true
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”)then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player.leaderstats.Cash.Value >= rc then
if debounce then
debounce = false
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 2500
script.Parent.Transparency = 0.5
script.Parent.CanCollide = false
if rc.Value <= rc then
script.Parent.Transparency = 0.5
script.Parent.CanCollide = true
end
end
end
end
end)

1 Like

Use Fire:Client(player) to help your needs.

Im sorry but where would i put that ?

maybe at the end of the script (before the ends obviously).

I’m not sure every time i type it in It says ‘global unknown fire’

you need an onClientEvent or something. You need a local script to receive that event “remote event too”.

111122233333; I have no clue what you’re trying to do.
If you could; at least next time; format your code to make it easier to read, use ``` these to format your code. Ex: ``` code ```
However, your entire system is flawed. A script runs on the server. That means anything it does replicates to all the clients. You have a few options here:
Use a localscript:
parent the localscript to a starterPlayer container (starterplayerscripts or startercharacterscripts) and change the script.Parent things to the path to the part that needs to be touched, and make sure you check that the player is the localplayer. However, this means it won’t change the cash value, so you need a client + server system.

Use remote events. Place one in ReplicatedStorage and name it whatever you want, and instead of

script.Parent.Transparency = 0.5
script.Parent.CanCollide = true

do this:

-- Server:
RemoteEvent:FireClient(player, script.Parent)

-- Client:
RemoteEvent.OnClientEvent:Connect(function(Part)
    Part.Transparency = 0.5
    Part.CanCollide = true
end)

@Styre_x
Okay so it worked! Tysm. But only thing is I have those all around the map lol would i have to repeat the step or would there be a more simple way like putting the local script into the door or would that break it?

just use one localscript, since it sends the part across the network it works no matter how many parts you have.