script.Parent.Touched:connect(function()
script.Parent.shop:Clone().Parent = game.Players.LocalPlayer.PlayerGui
print("done")
end)
that is the not working code please help me !
script.Parent.Touched:connect(function()
script.Parent.shop:Clone().Parent = game.Players.LocalPlayer.PlayerGui
print("done")
end)
that is the not working code please help me !
You're using a Server script, which can't access the LocalPlayer. A Server script has no idea who the client is. Every location (Starterpack, PlayerGui, StarterCharacterScripts, StarterPlayerScripts, etc..) that a LocalScript can be placed becomes in some way a descendant or child of a user when your player loads. However, place a LocalScript in workspace and that script is no longer associated with any player, because it's a child of workspace. This, however, doesn't mean you can't get the player from the part you touched.
This goes in a normal/server script.
local part = script.Parent
-- Use WaitForChild() on children
-- Scripts load before objects online
local shop = part:WaitForChild("shop")
-- Use 'C'onnect
part.Touched:Connect(function(hit)
-- Make sure hit didn't suddenly get destroyed
-- Hit is what hit the brick, like your leg.
if hit and hit.Parent then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
local char = player.Character
local humanoid = char:findFirstChild("Humanoid")
local player_gui = player:findFirstChild("PlayerGui")
-- Make sure we didn't reset on it and we don't already
-- have the shop
if humanoid and humanoid.Health > 0 and not player_gui:findFirstChild("shop") then
local shop_clone = shop:Clone()
shop_clone.Parent = player_gui
end
end
end
end)
This goes in a normal script inside of the part. You need to use GetPlayerFromCharacter, that way you can clone the GUI into their PlayerGui.
script.Parent.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local gui = script.Parent.ScreenGui:Clone()
gui.Parent = player.PlayerGui
end)
--Edit: Made a typo. My bad
If this helped, please upvote and accept answer! Thanks!
None of all the answers worked?!
What is your hierarchy?
Wut is that
Where is your script located and where is your Gui located.
Inside the part
Where is the ScreenGui located
also inside the part
its all located inside the part i want to be touched
Did you edit my answer at all? You might need to change line three to local gui = script.Parent.shop:Clone() , since your shop gui is named "shop" and not "Screengui". "ScreenGui" was an example.
i named the gui ScreenGui
Take a snapshot on where everything is located because I tested this script myself and It worked perfectly fine.
What is inside of the script? You must have made a typo or something.
script.Parent.Touched:Connect(function(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) local gui = script.Parent.ScreenGui:Clone() gui.Parent = player.PlayerGui end)
You probably have the outdated version of my answer in the script. Delete the contents and copy and paste my updated answer above. I made an accidental typo when I first submitted my answer. I apologize.
I already did that. ill do it again
I literally just tested it and it's working perfectly fine for me.
Not for me
Check the output and see if theres any errors.
No errors, It just won't work.. here is proofThat it should work http://prntscr.com/g71bzz
Well my answer definitely works. It might be because of your character or something. Did you use any custom character scripts?
Nope.. http://prntscr.com/g71cw8 im in R15 tho i don't think but maybe it has something to do with this? http://prntscr.com/g71d30
You have CanCollide turned off. You need to turn it on for it to work.
There is something wrong, if i click play the block just disappears
Is it Anchored?
yep
I don't know then. My script works 100%. Something in your game is screwing it up. Sorry.
Can you make it a model and send me the link?.
I guess
works..
Im so dumb the gui i had wasn't enabled?!?!?! Grrrr
Lol. Please accept my answer as I went through all this trouble to have it work for you,
--Sorry I forgot the Humanoid part!
Instructions
#1. Place the GUI in the part.
#2. place the script in the part
local gui = script.Parent.GUINAME
script.Parent.Touched:Connect(function(hit)
if hit.Parent.Name == 'Humanoid' then
gui:Clone().Parent = game.Players.LocalPlayer.PlayerGui
elseif hit.Parent.Name ~= nil then
gui:Remove().Parent = game.Players.LocalPlayer.PlayerGui
end
end)
That's incorrect. You need to use GetPlayerFromCharacter. You cannot index LocalPlayer from a normal script in the workspace.
Or you atleast need to get the player who touched the part.
Are you trying to make mine sound like it doesn't work so you could get upvoted?!
now I made it where if it finds the humanoid that touched the part then it opens it for the localplayer.
That is not the reason. The reason was is because your answer wouldn't work if I beginner tried to use it. Again, LocalPlayer can only be indexed from a LocalScript. Not a server script.
*A beginner
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
I want to make it so if the player touches the part it gives the player the shop gui and opens it