I want to have the character when touching the marker to have it disappear, but the main thing I am trying to accomplish is just having the character touch the marker and it recognizes it!
There is a twist with my system here that makes it difficult for me, the bike and character are only on the client as it is replicated to all clients. The markers are also on the client, but I want to have it so the character is the only thing that when touched by the marker (vice versa) it prints “Touched” or rather goes through with the code.
The way the markers are introduced is, they are in the Replicated storage in a folder and they are called by a local script to come into the workspace so that they are on the client (This is a one-person time trial).
CodeBlueLeaderBoard.IconButton.IconSurface.ImageButton.MouseButton1Click:Connect(function()
print("Trial Initiated")
wait(0.25)
StartTrial()
wait()
LoadMarkers()
end)
function StartTrial()
wait()
CHARACTER.Anchored = true
wait()
CHARACTER.Position = CodeBluePassive.SPAWN_LOC.Position
workspace.Ignore:WaitForChild(PLAYER.Name.."Bike").Frame.Position = CodeBluePassive.SPAWN_LOC.Position
wait()
CHARACTER.Velocity = Vector3.new(0,0,0)
workspace.Ignore:WaitForChild(PLAYER.Name.."Bike").Frame.Velocity = Vector3.new(0,0,0)
wait(1)
print("1")
wait(1)
print("2")
wait(1)
print("3")
CHARACTER.Anchored = false
end
function LoadMarkers()
for index, CBPassiveChildren in pairs(CBPassiveChildren) do
print(CBPassiveChildren.Name)
CBPassiveChildren.Parent = workspace.TimeTrials.CodeBlueActive
end
print("Code Blue Markers Generated")
end
This is how the markers are generated, an icon on a leaderboard is pressed and that calls for the character to teleport into place. The markers are then loaded into the workspace into a specific folder called CBActive. When they are in the RepStor, they are in a folder called CBPassive.
How exactly would I accomplish only allowing the Character to touch the marker? Please ask if you need any more explanation! Thank you!!!
If the script above is a localscript, all data wouldn only “locally” be loaded into the game. A player could then easily “exploit” by just saying it has touched the part without the server verifying it.
I would load all the checkpoints serverside and connect a touched event to it:
local players = game:GetService("Players")
for i, checkpoint in pairs(checkpointsFolder:GetChildren()) do
checkpoint.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = players:GetPlayerFromCharacter(hit.Parent)
if player then
--handle the action when a player has touched it and check if its the right player
end
end
end)
end
if it is all clientside and you really want to keep it that way, send the server a remote when the client is touching one of the checkoints and let the server check whether the checkpoint really exists and whether the player is really there. You could use magnitude for checking the distance from the player and the checkpoint for example.
If I need to verfiy the function to where it is not accesible by exploiting, I can make the local script call to the server and the server can send the signal back to the local script replicating it on the client and it still being safe. I had done this with my customization so that the client side and other clients can see the changes and it still goes through the client.
This is where the character model and bike are stored. This is a signal sent to the server and then sent back to the client where it is fired on all clients.
If its all locally brought into workspace, you can still connect a touched event to all of the checkpoints via the localscript and handle the touching there to make the checkpoint disappear