Creating a Shop Field

So I’m making a shop field which if you step in it…


A window like this pops up!

Pretty basic thing, but how do I script the field to keep the shop up whilst the player is standing in it?

Note: The planned process is like this:
Step in field > Shop window tweens in and background fades > player browses for a bit > leaves field > shop tweens out and background returns to normal

I do know how the tweening and background fading should be scripted, I just need to know how to script the main question.

4 Likes

Well you can do this: When player step on brick it will detect player and then you can do remote event for GUI to pop in:
Something like this
Script in part
script.Parent.Touched:Connect (function (hit)
if hit.Parent then
local humanoid = hit.Parent:WaitForChild (“Humanoid”)
if humanod then
local player = game.Players:GetPlayerFromCharacter (hit.Parent)
game.ReplicatedStorage.Event:FireClient (player, true)
end
end
end)
local script in GUI:
game.ReplicatedStorage.OnClientEvent:Connect (function (toOpen)
if toOpen == true then
script.Parent:WaitForChild (“Frame”).Visible = true
else
script.Parent:WaitForChild (“Frame”).Visible = true
end
end)

You can use TouchEnded to detect when player is no lomger touching brick and all you have to change is passing value fo false:
game.ReplicatedStorage.Event:FireClient (player, false)
I hope this helps, also mark this as solution if it works :slight_smile:

1 Like

Thanks for your advice, but there’s a few problems…

There’s this error here…
Screenshot 2020-04-06 at 02.37.23
And I’ve got the RemoteEvent here, but an error is being detected here.

That’s because player isn’t defined in that scope/function. You are only defining it in script.Parent.Touched. You need to also find the player in that event. But, there is most likely going to be some obstacles in this, which is why I would recommend you use raycasting. Every x amount of seconds, raycast down from the player’s torso, and if the ray hits a part with a specific name, then you open up the shop UI! This works great, and is a lot easier than what you’re trying to do.

2 Likes

Interesting. I’d better study raycasting. Thank you for notifying me!
I’m looking at the article on the Wiki right now. Any other advice?

I’m also getting this feeling that if I have the ray being cast with x being just wait(), something bad might happen performance-wise or something.

1 Like

In the way that I suggested you raycast, you shouldn’t noticed any issue with performance.

Not sure what you mean. I mean every X amount of seconds. wait(yourtimehere) in a loop. You can also try doing it in renderstepped or a related event. You can always experiment and get back to me if you have any issues with performance :slight_smile:

2 Likes

Not RenderStepped. Only use that if you need something to happen before a frame renders. Checking where a player’s place is in the world before flipping a flag is not something worthy of being done before a frame renders. Use Heartbeat.

@Xenothekid Rays are only expensive (performance heavy) when they’re long. You are able to fire off hundreds of rays per frame with no noticeable delays.

2 Likes

I’ve managed to write my own method to solve the major problem, but now there’s a problem with debouncing…

On line 5, you made a spelling error. You spelled “humanoid” as “humanod”

I got it working but its not best method but still … it works


instead of touched I used 2 colliders for Touched

Here is the script:

local Shop = game.ReplicatedStorage.Shop

local debounce = false

script.Parent.Touched:Connect(function(hit)
	if not debounce then	
		local humanoid = hit.Parent:FindFirstChild("Humanoid") 
			if humanoid then
				local player = game.Players:GetPlayerFromCharacter(hit.Parent)

				print("Welcome!")
				Shop:FireClient(player, true) -- true mans open
				debounce = true
				
			end
		end
end)


script.Parent.Union.Touched:Connect(function(hit)
	if debounce then	
		local humanoid = hit.Parent:FindFirstChild("Humanoid") 
			if humanoid then
				local player = game.Players:GetPlayerFromCharacter(hit.Parent)

				print("Goodbye!")
				Shop:FireClient(player, false) -- true mans open
				debounce = false
			end
		end
end)

-- local script in gui:

game.ReplicatedStorage.Shop.OnClientEvent:Connect(function(toOpen)
	if toOpen then
		script.Parent.Visible = true
	else 
		script.Parent.Visible = false
	end	
end)
1 Like