Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to get a simulator shop working on touch?

Asked by
zapzser -3
4 years ago

ME and my friend made a simulator and we have made a proper sell button and shop button and the GUIs, but the shop GUI does not come up when touched here is the code so you can take a look at it:

game.Workspace.ShopPart.Touched:Connect(function(hit) if hit then script.Parent.Shop.Frame.Visible = true end end)

0
That should work tbh awsomecoolbruh -10 — 4y
0
yeah actually that should work hot_spi 20 — 4y

1 answer

Log in to vote
0
Answered by
souflee 50
4 years ago

Hey there,

First off it's important to keep in mind that if you have multiple parts that can be touched this won't work. You should add an onTouched script into the part itsself if this is the case.

Second off, you can't make a gui visible from the server, you should try to clone the gui into the playerGui. This, in turn, is something you can do with the GetPlayerFromCharacter() command. In the end your script should look something like this (although you may need to edit it a bit).

local taken = false

script.Parent.Touched:Connect(function(hit) if hit then 

if part.Parent:FindFirstChild("Humanoid") then
local plr = players:GetPlayerFromCharacter(part.Parent)
    if taken == false then
        taken = true
game.ReplicatedStorage.Gui:FindFirstChild("Shop"):Clone().Parent = plr.PlayerGui
end
end
end)

If this helped, please accept it as your answer. If it didn't - feel free to ask away! ^^

0
OK so I am confused I need to make an on-touched script or is this the on-touched script and I can keep the old script. And also, where should I put these script under(The part?, The StarterGUI?) zapzser -3 — 4y
0
The script I posted should work as an onTouched script. You may need to edit some variables or strings, though. I would place the script inside the part. You should place the Gui in a folder named "Gui" in the ReplicatedStorage. souflee 50 — 4y
Ad

Answer this question