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

How do i detect a player that stepped on a certain part?

Asked by
v_amp 6
4 years ago

I need a script to log the players name if they've stepped on a part.

1 answer

Log in to vote
0
Answered by
Koap2 17
4 years ago

This can be done by using this code

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local part = <Put part identifier here>
part.Touched:Connect(function(hit)
if hit ~= nil then
local PlayerName = hit:GetFullName()
local StringValue = Instance.new("StringValue")
StringValue.Parent = <StringValue's parent>
StringValue.Value = tostring(PlayerName)
end)

Here, it has also created a string value so that it can be stored in DataStore, ReplicatedStorage, or any other place. To make identification of the StringValue easier, assign it a unique name like:

StringValue.Name = tostring(PlayerName).."_StringValue"
0
Thanks, you might wanna edit your code and add another "end" before the function ends for anyone else trying to use this code v_amp 6 — 4y
Ad

Answer this question