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)
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
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
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’)
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)