So im devloping a game, and there’s like a shop in spawn,
i want it so that when a player touched the Shop part, the Shop Gui is visible.
So i tried to do this in Server Script Service
local ArmorShopPart = game.Workspace.Spawn.ArmorShopPart.ShopGui.ShopPart
ArmorShopPart.Touched:Connect(function(Plr)
if Plr.Parent:FindFirstChild("Humanoid") then
game.ReplicatedStorage.OpenArmorShopEvent:FireClient(Plr.Name)
end
end)
and this in Starter Player Scripts
local Event = game.ReplicatedStorage.OpenArmorShopEvent
Event.OnClientEvent:Connect(function(Player)
if game.Players.LocalPlayer.Name == Player then
game.PlayerGui.ArmorShopGui.MainFrame.Visible = true
game.PlayerGui.ArmorShopGui.BgFrame.Visible = true
end
end)
But it gave me this error
“Unable to Cast Value to Object”
and the line the error showed me was
local ArmorShopPart = game.Workspace.Spawn.ArmorShopPart.ShopGui.ShopPart
ArmorShopPart.Touched:Connect(function(Plr)
if Plr.Parent:FindFirstChild("Humanoid") then
game.ReplicatedStorage.OpenArmorShopEvent:FireClient(Plr)
end
end)
Pass in the player instance not the name of the player.
local ArmorShopPart = game.Workspace.Spawn.ArmorShopPart.ShopGui.ShopPart
ArmorShopPart.Touched:Connect(function(Plr)
if Plr.Parent:FindFirstChild("Humanoid") then
game.ReplicatedStorage.OpenArmorShopEvent:FireClient(Plr)
end
end)
then this script would be like this?
local Event = game.ReplicatedStorage.OpenArmorShopEvent
Event.OnClientEvent:Connect(function(Player)
if game.Players.LocalPlayer == Player then
game.PlayerGui.ArmorShopGui.MainFrame.Visible = true
game.PlayerGui.ArmorShopGui.BgFrame.Visible = true
end
end)
or like this?
local Event = game.ReplicatedStorage.OpenArmorShopEvent
Event.OnClientEvent:Connect(function(Player)
if game.Players.LocalPlayer.Name == Player then
game.PlayerGui.ArmorShopGui.MainFrame.Visible = true
game.PlayerGui.ArmorShopGui.BgFrame.Visible = true
end
end)
local ArmorShopPart = game.Workspace.Spawn.ArmorShopPart.ShopGui.ShopPart
ArmorShopPart.Touched:Connect(function(Plr)
if Plr.Parent:FindFirstChild("Humanoid") then
game.ReplicatedStorage.OpenArmorShopEvent:FireClient(Plr)
end
end)
local Event = game.ReplicatedStorage.OpenArmorShopEvent
Event.OnClientEvent:Connect(function(Player)
if game.Players.LocalPlayer == Player then
game.PlayerGui.ArmorShopGui.MainFrame.Visible = true
game.PlayerGui.ArmorShopGui.BgFrame.Visible = true
end
end)
but it says this
" FireClient: player argument must be a Player object "
pls help @Mystxry12
local ArmorShopPart = game.Workspace.Spawn.ArmorShopPart.ShopGui.ShopPart
ArmorShopPart.Touched:Connect(function(TouchedPart)
if TouchedPart.Parent:FindFirstChild("Humanoid") then
local Character = TouchedPart.Parent
local plr = game.Players[Character.Name]
game.ReplicatedStorage.OpenArmorShopEvent:FireClient(plr)
end
end)
Also you don’t need the “if game.Players.LocalPlayer == Player then” so just put
You can add an if statement to see if the MainFrame is visible or not though, or even a debounce so the player isn’t constantly spammed by the Frame whenever they move on the shop part
something like this could do it (it’s not perfect, but it will do the job)
local Event = game.ReplicatedStorage.OpenArmorShopEvent
local db = false
Event.OnClientEvent:Connect(function(Player)
if db or game.PlayerGui.ArmorShopGui.MainFrame.Visible then return end
db = true
game.PlayerGui.ArmorShopGui.MainFrame.Visible = true
game.PlayerGui.ArmorShopGui.BgFrame.Visible = true
repeat task.wait() until game.PlayerGui.ArmorShopGui.MainFrame.Visible == false
task.wait(1)
db = false
end)
Ayyy, I figured it Out, @paetemc2 ur code didnt work, here is the code which worked for me
ServerScriptService :-
local ArmorShopPart = game.Workspace.Spawn.ArmorShopPart.ShopGui.ShopPart
ArmorShopPart.Touched:Connect(function(TouchedPart)
if TouchedPart.Parent:FindFirstChild("Humanoid") then
local Character = TouchedPart.Parent
local plr = game.Players[Character.Name]
game.ReplicatedStorage.OpenArmorShopEvent:FireClient(plr)
end
end)
and in the Starter Player Scripts :-
local Event = game.ReplicatedStorage.OpenArmorShopEvent
local db = false
Event.OnClientEvent:Connect(function(Player)
local Plr = script.Parent.Parent
if db or Plr.PlayerGui.ArmorShopGui.MainFrame.Visible then return end
db = true
Plr.PlayerGui.ArmorShopGui.MainFrame.Visible = true
Plr.PlayerGui.ArmorShopGui.BgFrame.Visible = true
repeat task.wait() until Plr.PlayerGui.ArmorShopGui.MainFrame.Visible == false and Plr.PlayerGui.ArmorShopGui.BgFrame.Visible == false
task.wait(1)
db = false
end)