Trying to make door charge if CanCollide is true

So I have tried many ways to make a buyable door, and the last try was this one, which isn’t working either.
It keeps running the money substraction line each time I try to pass trought, regardless of the line of code (Even after CanCollide is changed to false in the local script):
if game:GetService(“Players”)[hit.Parent.Name].leaderstats.Coins.Value >= 100000 and Portal == true then

Server script:

local debounce = false

script.Parent.Touched:Connect(function(hit)

	if hit.Name == "HumanoidRootPart" then

		if not debounce then

			debounce = true


			local Portal = game:GetService("Workspace").World01.Essentials.Portal1.Portal1Collider.CanCollide

			if game:GetService("Players")[hit.Parent.Name].leaderstats.Coins.Value >= 100000 and Portal == true then

				local Coins = game:GetService("Players")[hit.Parent.Name].leaderstats.Coins

				Coins.Value = Coins.Value - 100000

				game:GetService("ReplicatedStorage").CheckPortalData:FireClient(game:GetService("Players")[hit.Parent.Name], "Portal1")

			end

			wait(1)

			debounce = false

		end

	end

end)

LocalScript:

game:GetService("ReplicatedStorage").CheckPortalData.OnClientEvent:Connect(function(portal)
	
	
	if portal == "Portal1" then
				
		game:GetService("Workspace").World01.Essentials.Portal1.Portal1Collider.CanCollide = false
		
		game:GetService("Workspace").World01.Essentials.Portal1.Gui.Transparency = 1

		game:GetService("Workspace").World01.Essentials.Portal1.Gui.SurfaceGui.TextLabel.Visible = false
		

	end

end)

My brain hurts just by looking at all those spaces aaa

I think I see a couple of errors & reasons why, and I went ahead and fixed up your script’ish hopefully? Lemme know what happens:

--Server Script
local debounce = false
local ReplicatedStorage = game:GetService("ReplicatedStorage")

script.Parent.Touched:Connect(function(hit)
	local Character = hit.Parent
	local Player = game.Players:GetPlayerFromCharacter(Character)
	if Character:FindFirstChild("HumanoidRootPart") and Player and not debounce then
		debounce = true
		local Portal = game:GetService("Workspace").World01.Essentials.Portal1.Portal1Collider.CanCollide
		local PortalNum = "Portal1"
			if Player.leaderstats.Coins.Value >= 100000 and Portal == true then
				local Coins = Player.leaderstats.Coins
				Coins.Value = Coins.Value - 100000
				ReplicatedStorage.CheckPortalData:FireClient(Player, PortalNum)
			end
		wait(1)
		debounce = false
	end
end)

--Local Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")

ReplicatedStorage.CheckPortalData.OnClientEvent:Connect(function(PortalNum)
	if PortalNum == "Portal1" then
		game:GetService("Workspace").World01.Essentials.Portal1.Portal1Collider.CanCollide = false
		game:GetService("Workspace").World01.Essentials.Portal1.Gui.Transparency = 1
		game:GetService("Workspace").World01.Essentials.Portal1.Gui.SurfaceGui.TextLabel.Visible = false
	end
end)

First. Thank you for your time here.

And sorry for the spaces, for me it’s the other way around, I get lost when everything is smooched togeter

Saddly that did not work either:

https://i.gyazo.com/5783190b14643b9f32dd73e1b081f88e.mp4

Ah you’re fine :sweat_smile: Wait, so are you trying to check if the CanCollide to the door is set to true on the client?

I am trying to prevent the script from subtracting 100000 if CanCollide is false, because as seen in the video provided above, even if cancollide and transparency are modified, the door still removes the Coins when Touched. I tried other ways to make the door, like disabling the script on the localscript, but than a weird thing happened where when I stepped on the sell part, it would set the Coins back to what it was before I bought the door.

And yes on the client… I think, I am still learning lol

You could make a folder or table with the players who unlocked that portal.

Hum, havent thought about that, I will give it a try tomorow! thank you dear.

Or make the purchase by the client instead of the server.
Is more simple ^-^

Ah I see, you’re fine though! Everyone learns but I’ll try to explain how client and server sided are different:
So in your place there are 2 sides: A client and a server

The client side is only visible to those themselves (Or your ROBLOX client if you wanna put it like that)

And the server side is visible to everyone, or the entire game

Both the server & client side are different from each other, so trying to change the Portal1 Collision from the client will of course, only be that certain client while changing it from the server instead will change it for everyone

1 Like

(You could do a leaderboard purchase on the client but it won’t be visible to other players, just keep in mind that)

1 Like

Ah so the LocalScript would be Client side and the Script would be Server side?

Correctamundo! It’s quite interesting how much you can really do with these 3 scripts :sweat_smile: (Local, Server, & Module)

Yes lol when it’s time for the Datastore, I want to try and make it as a module script. I am really not there yet thought XD

Practice makes perfect, after all! Relating to SOTR’s post, you could place a BoolValue on the Player to check if they have the portal unlocked or not, then work on what changes to be made on the client (Why the heck did I say ‘cllient’)

Use this code:

local Players = game:GetService("Players")
Player = Players.LocalPlayer
Portal =  --| Location of the part that must let the player pass

Portal.Touched:Connect(function(hit)
    if hit.Parent.Name == Player.Name then
	    local Coins = Player.leaderstats.Coins
    	if Coins.Value >= 100000 and Portal.CanCollide == true then
	    	Coins.Value = Coins.Value - 100000
		    Portal.CanCollide = false
    		Portal.Transparency = 1
	    	----| Rest of the code |----
		
		    ----------------------------
	    end
    end
end)

And place it here:
Code

Worked great, had I known, i wrote a similar script before trying all sorts of waky stuff, but it was in a script and not a localscript lol TY!

You’re welcome, happy to help ^-^