Leaderstats Door UI not working

I tried to create it so that when you touch a door then this UI appears but it does not
This one:


This is the error it gives:

Please ignore the error message that says “you must publish to access the DataStore” it from an another script. Just see the first one that is the real error

This is the script by the way:
This script in inside the door part

local Player = game.Players.LocalPlayer 
local PlayerGui = Player.PlayerGui 
local Frame = PlayerGui.LeaderstatsDoorUI.LeaderstatsDoorFrame 
local Button = PlayerGui.LeaderstatsDoorFrame.BuyButtonUI
local Button2 = PlayerGui.LeaderstatsDoorFrame.CloseButtonUI



local RequiredCoins = 2000

local debounce = true
script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
			Frame.Visible = true
		
	end
end
end)

The second script is this and is inside of:

local leaderstatsDoor = game.Workspace.Door1
local player = game.Players.LocalPlayer
local RequiredCoins = 2000
script.Parent.MouseButton1Click:Connect(function()
	if player.leaderstats.Coins.Value >= RequiredCoins then
		leaderstatsDoor.Transparency = 1
		leaderstatsDoor.CanCollide = false
	elseif player.leaderstats.Coins.Value < RequiredCoins then
		leaderstatsDoor.Transparency = 0.5
		leaderstatsDoor.CanCollide = true
	end
end)

It is inside of this:
image

Could anyone please do help me out

From what it looks like, you got an error because you didn’t allow your place to access the DataStoreService (which you can do by publishing your place and switching on the button in the “Security” section of the game’s settings.)

In your first script you have an extra end that you don’t need.

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		    Frame.Visible = true
        end -- closes the if statement

-- end: extra end, you don't need this one

end) -- closes the function used for the touched event

As an aside, indenting your code can help you to know where an `end` needs to be put.
script.Parent.Touched:Connect(function(hit) -- 1 tab for function contents
	if hit.Parent:FindFirstChild("Humanoid") then -- 2 tabs if statement contents
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		Frame.Visible = true
    end -- end lines up with if clause
end) -- end lines up with function clause

uhm ya actually that is the error from another script just ignore that, the first one is the real error

Oh ok. You should make sure to fix it though.

If @GreatPanda3’s reponse helped you, you might wanna mark it as the “Solution” post.

Actually it did not work no errors too, I don’t know what is the problem

ya but it actually did not work

I see.

Something I usually do when a script does not work but doesn’t show me any errors, I put a print(“Test”) around every 1-2 lines or so. You could try doing that and see what’s the problem to where the prints stops.

Can you show the part of the explorer menu where your door script is?

Players.LocalPlayer doesn’t work in normal scripts. Instead you can use this script.

local RequiredCoins = 2000

local debounce = true
script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
		local PlayerGui = Player.PlayerGui 
		local Frame = PlayerGui.LeaderstatsDoorUI.LeaderstatsDoorFrame 
		local Button = PlayerGui.LeaderstatsDoorFrame.BuyButtonUI
		local Button2 = PlayerGui.LeaderstatsDoorFrame.CloseButtonUI
		Frame.Visible = true

	end
end)
1 Like

image

As @ALL_roblox62 said, you cannot use game.Players.LocalPlayer in a server-script.

You could use the method he used, or, use a for i,v in pairs() to find the player.