Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Door will open for everyone on the server, why?

Asked by 3 years ago

Hello! So I have a door script here that the rc (required cash) is supposed to be 5k to enter but the thing is that when someone opens it, every noob can go through that door. I've thought of making something like closing after going through it, but it would close forever so I'm left with the door that lets anyone enter even if they dont have 5k

TL;DR someone with 5k cash goes through door, then everybody can go through that door.

local rc = 5000
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
                script.Parent.Transparency = 0.5
                script.Parent.CanCollide = false
                if rc.Value <= rc then
                    script.Parent.Transparency = 0.15
                    script.Parent.CanCollide = true
                end
            end
        end
    end
end)


0
forgot to mention. It's a script so that might be the problem. I thought of doing LocalScript but it ends up not working at all qMrSpooky 20 — 3y

3 answers

Log in to vote
0
Answered by
imKirda 4491 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

You are right, use Local Script. The reason why this does not work as a local script is because you probably put it into the workspace, instead, put it into StarterPlayerScripts and change variables from script.Parent to workspace:WaitForChild("What you need here") (Wait for child because it might not replicate when the script runs in starter player)

0
I'm gonna try! =] qMrSpooky 20 — 3y
0
IT WORKED! qMrSpooky 20 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
local rc = 5000
local debounce = true
workspace:WaitForChild("Door1").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
                script.Parent.Transparency = 0.5
                script.Parent.CanCollide = false
                if rc.Value <= rc then
                    script.Parent.Transparency = 0.15
                    script.Parent.CanCollide = true
                end
            end
        end
    end
end)

neither this worked

0
Is it a Local Script? BestCreativeBoy 1395 — 3y
0
you forgot to change script.Parent to workspace:WaitForChild("Door1") so it gave you some error like: Transparency is not valid member of... You would have to change all the 4 script.Parent's to the door.  This is why it is very important to use variables, you would just have to change one. imKirda 4491 — 3y
0
Also yo bestCreativeBoi reverse my reputation, you will get yours ^^ imKirda 4491 — 3y
0
yo ok ty qMrSpooky 20 — 3y
Log in to vote
0
Answered by 3 years ago

I know this might seem odd, but a pretty simple way to set this up is to use the PhysicsService to isolate a group of allowed players from the group of disallowed players. If you are aware of how to use the service, that's good. If not, here's a brief explanation of what it does and how useful it can be.

Basic initialization:

local PhysicsService = game:GetService("PhysicsService")
-- Now you create the collision groups. These can be named anything you want.
PhysicsService:CreateCollisionGroup("Name1")
PhysicsService:CreateCollisionGroup("Name2")
-- etc.

By creating collision groups you are starting to set up what can collide with something or what is unable to collide with something. The PhysicsService is very useful for making certain models be able or unable to collide with one another.

So now, because the PhysicsService only takes BasePart instances in its collision groups, you need to loop through the player's Character and enter every individual part into a collision group. Something like this, you might think:

for i,v in pairs(player.Character:GetChildren()) do -- player can be defined through something else, like PlayerAdded or GetPlayerFromCharacter()
    if v:IsA("BasePart") then
        PhysicsService:SetPartCollisionGroup(v, "NameofGroup")
    end
end

The door that you seek to set collidable can be added to the second group, if desired.

Next is a basic function of the service called CollisionGroupSetCollidable(n1, n2, bool). This function sets the collision of n1 and n2 to the value of bool, which must be either true or false. I'm pretty sure you can figure this one out by yourself.

Now, I personally don't seek opposition to using a local script, but in my opinion, you should use PhysicsService over client-sided CanCollide. It makes your life that much easier.

Answer this question