Hi guys, I’m trying to make a game where when a player is standing on “part1” AND a player is standing on “part2” then an event happens…Here is my code.
`–PLAYER1 START CODE
local player1Start = game.Workspace.Player1
local player1Ready = false
if player1Ready == true then
print(“SUCCESSS”)
end`
As you can see I put that print code at the end to show that the variable isnt being carried outside the function, any ideas how I could make a variable to show that both players are on the parts? Thanks for any help!
No they are still useless, but your code itself is not going to work well in practice. You need to rewrite it. I deleted because @Pegagittt said they would rewrite the script.
Oh ok, yeah i have been trying to script this for ages and keep starting again from scratch because i keep encountering massive problems with my script
Dont use Touched Event for Player, use Touched Event for the Part. You code would make many buggs, because it has no secure.
I made a Code rn, Try this Code under me:
Insert your part Location in part1 and part2 Variable.
Make your Part Cancollide = false and Anchored = true
Server:
local part1 = game.Workspace.Part1
local part2 = game.Workspace.Part2
local standingOnPart1 = false
local standingOnPart2 = false
local standingTable = {}
local function startEvent()
if standingOnPart1 == true and standingOnPart2 == true then
local player1 = game:GetService("Players"):GetPlayerByUserId(part1.Name)
local player2 = game:GetService("Players"):GetPlayerByUserId(part2.Name)
game.ReplicatedStorage:WaitForChild("RemoteEvent"):FireClient(player1)
game.ReplicatedStorage:WaitForChild("RemoteEvent"):FireClient(player2)
standingOnPart1 = false
standingOnPart2 = false
part1.Name = "part1"
part2.Name = "part2"
end
end
part1.Touched:Connect(function(touched)
local playerTouchedOrNot = game:GetService("Players"):GetPlayerFromCharacter(touched.Parent)
if playerTouchedOrNot then
if standingOnPart1 ~= true and part2.Name ~= playerTouchedOrNot.Name then
standingOnPart1 = true
part1.Name = playerTouchedOrNot.UserId
startEvent()
end
end
end)
part1.TouchEnded:Connect(function(touched)
local playerTouchedOrNot = game:GetService("Players"):GetPlayerFromCharacter(touched.Parent)
if playerTouchedOrNot then
if standingOnPart1 ~= false and part1.Name == playerTouchedOrNot.Name then
standingOnPart1 = false
part1.Name = "part1"
end
end
end)
part2.Touched:Connect(function(touched)
local playerTouchedOrNot = game:GetService("Players"):GetPlayerFromCharacter(touched.Parent)
if playerTouchedOrNot then
if standingOnPart2 ~= true and part1.Name ~= playerTouchedOrNot.Name then
standingOnPart2 = true
part2.Name = playerTouchedOrNot.UserId
startEvent()
end
end
end)
part2.TouchEnded:Connect(function(touched)
local playerTouchedOrNot = game:GetService("Players"):GetPlayerFromCharacter(touched.Parent)
if playerTouchedOrNot then
if standingOnPart2 ~= false and part2.Name == playerTouchedOrNot.Name then
standingOnPart2 = false
part2.Name = "part2"
end
end
end)
Client:
local visibleFrameOrOthers = "Insert your Frame, TextLabel, TextBox or others Location in here, if its a ScreenGui u need to use Enabled instead of Visible."
game.ReplicatedStorage:WaitForChild("RemoteEvent").OnClientEvent:Connect(function()
visibleFrameOrOthers.Visible = true -- If you want to make a ScreenGui Visible then you need to replace `Visible` with `Enabled`.
end)
Well; from the looks of it, you’re modifying StarterGui which wont replicate to the player’s clients since they all have copies of the GUI in game.Players[name].PlayerGui