Hello, as the title says i have made a barrier and i want it to unlock if the player has enough money for it but the barrier only to unlock for the person buying it, i have leaderstats set up and working, i have made a way of actually getting money, the barrier works just fine but it opens for everyone on the server.
It is already a Local script and it is located inside StarterPlayer in StarterPlayerScripts.
Here’s the script i made:
local Barrier = game.Workspace.UnlockableZone1.Barrier
Barrier.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player.leaderstats.Coins.Value >= Barrier.Requirement.Value then
player.leaderstats.Coins.Value -= Barrier.Requirement.Value
Barrier.Transparency = 1
Barrier.CanCollide = false
Barrier.SurfaceGui.Enabled = false
Barrier.CanTouch = false
end
end
end)
I have tried putting the script inside ServerScriptService or inside StarterGui but it doesn’t work, the barrier opens for everyone not only just for the player buying it.
And i have tried changing the script in many different ways but still doesn’t work, if someone can help me and find the error i would appreciate it a lot.
Don’t use a local script, a server script can handle it on it’s own.
Then you need to have it where there is a check on the part touch, and if the player already owns it, to allow them to pass through.Then you can use a surface gui for the part to have effects, and make the part’s transparency 1 by default.
Add two groups e.g. “Barriers” & “UnlockedBarrierPlayers” and set those two groups to not collide. Then only add players that have unlocked it to the “UnlockedBarrierPlayers” group.
This helps with the collision but the visibility would still change for everyone else tho, thanks for helping with the collisions ill try finding a way to make the visibility only change for a player
You will have to use a method like creating server-side script, local one and use a remote event for communication.
Here are the details:
Create a remote event and place it in replicated storage.
Create a server script which will detect a barrier touch and check if the toucher is allowed to unlock the barrier. If they are, the script fires the remote event to this player.
Create a local script which will be listening to the earlier remote event. You can then make this barrier unlocked on this player’s machine based on that.
Hello i have an issue, this worked for a while but i dont know why it stopped working today, maybe my friends wanted to see what scripts i have done and they changed something in the script cause im working on a game on Team Create but i cant find what they changed (if they changed anything) and why it doesn’t work, if you can please help me i would appreciate it a lot,
local Barrier = game.Workspace.UnlockableZone1.Barrier
local RemoteEvent = game.ReplicatedStorage.UnlockableZone1Event
Barrier.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player.leaderstats.Coins.Value >= Barrier.Requirement.Value then
RemoteEvent:FireClient(game.StarterPlayer.StarterPlayerScripts.UnlockableZone1LocalScript)
end
end
end)
this is the server side script
local Barrier = game.Workspace.UnlockableZone1.Barrier
local player = game.Players.LocalPlayer
player.leaderstats.Coins.Value -= Barrier.Requirement.Value
Barrier.Transparency = 1
Barrier.CanCollide = false
Barrier.SurfaceGui.Enabled = false
Barrier.CanTouch = false
This is the local script
I cant find the issue why it opens for everyone now, i have created a remote event in replicated storage, i would appreciate it REALLY MUCH if you helped me but if you cant help me its okay, i understand.
Oh and btw by not working i mean the barrier opens for everyone on the server not just for the client opening it.
Edit: It doesn’t even open the barrier anymore the first time i tested it did but now it didn’t, i didn’t change anything in the script from then to now, i dont understand why this happened, i would appreciate any help really really much but if you cant help me i understand.
Ohh i think that’s it, i think my friends changed that in the code and i didn’t notice, thanks ill make it again then test it to see if it works, sorry for bothering but i didn’t notice it
Hmm i dont understand, when i tested it yesterday it worked, it was the same script just the local script was actually listening to the remote event, i fixed that and i changed in the server script for the first argument to be a player object and now it works properly but i dont understand how it worked yesterday without the first argument being a player object.