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.
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
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.
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
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.
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)