Nvm i just did this
if HasBadge == false then
print("Player has badge, make door visible or transparent!")
end
end)
Nvm i just did this
if HasBadge == false then
print("Player has badge, make door visible or transparent!")
end
end)
Oh if they dont have the badge? okay so then do if not HasBadge
I think the Solution was found,
Things you could improve on are Variable Names, always use local for organization
Next is before trial and erroring read the documentaries of every Roblox Service, for example BadgeService so you know the correct functions and calls that BadgeService has.
Whenever a function requires checking Roblox api, wrap it in a pcall
A pcall is essentially a protected call, making sure that if it errors the script still runs completely fine.
If you found this helpful, mark as a solution
So where do I put the event in scripts to make it only do it for the local player?
The function UserHasBadgeAsync() is pnly available to the Server
To make changes to the client, communicate to the client via a RemoteEvent
Learn more about RemoteEvents on the devforum as they are a bit complicated and somewhat hard to explain to beginners
you have to create a remote event object in ReplicatedStorage, then reference it in the server and then fire it to whoever doesn’t have the badge in the server script.
Then all you need is just a localscript in starter player scripts which attaches a listener to the event that turns the door invisible.
BadgeService:UserHasBadgeAsync
“When calling the method from the client in a LocalScript, it only works for the local user whose client is running the script.”
UserHasBadgeAsync
can be called on the client. It can only query information about the local player. Since the door should only be removed for each client who owns the badge, each client can query whether or not they own the badge and remove the door if so.
On another note, when using remote events to notify clients of information at the moment of entry to the server, there is high chance a client may not connect a listener to RemoteEvent.OnClientEvent in time. It is best you let the server wait on the client to request said information. This is implemented through a RemoteFunction
Ahhh good point, i forgot that you can get if the localplayer has a badge… Thanks for reminding me
edit; i literally cant see out of my left eye and its burning really bad
I think I figured it out! I put a local script in StarterPlayerScripts:
local Players = game:GetService("Players")
local event = game.ReplicatedStorage.JoinEvent
Players.LocalPlayer.CharacterAdded:Connect(function(character)
event:FireServer()
end)
And then I added this to the original script:
local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")
local badgeid = script.Parent.Parent:WaitForChild("BadgeID")
local function playerGates(player)
--player returns playerobject in game.Players
local Character = player.Character
local HasBadge, Result = pcall(function()
return BadgeService:UserHasBadgeAsync(player.UserId, badgeid)
end)
if HasBadge == false then
print("Player has badge, make door visible or transparent!")
end
end
local event = game.ReplicatedStorage.JoinEvent
event.OnServerEvent:Connect(function(player)
playerGates(player)
end)
The script works fine I just need the script to detect if the player has badge or gamepass. I have the gamepass but it is not working:
local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")
local badgeid = script.Parent.Parent:WaitForChild("BadgeID")
local gamepassid = script.Parent.Parent:WaitForChild("GamepassID")
local MarketplaceService = game:GetService("MarketplaceService")
local function playerGates(player)
--player returns playerobject in game.Players
local Character = player.Character
local HasBadge, Result = pcall(function()
return BadgeService:UserHasBadgeAsync(player.UserId, badgeid)
end)
local HasGamepass, Result = pcall(function()
return MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamepassid)
end)
if HasBadge == false then -- Detects if player doesnt have badge
if HasGamepass == false then -- Detects if player doesnt have gamepass
game.Workspace.Gate2.TouchGateScript.Enabled = false
end
end
end
local event = game.ReplicatedStorage.JoinEvent
event.OnServerEvent:Connect(function(player)
playerGates(player)
end)