I am trying to make a part change color when it detects it is me in the localscript, and I need help. does anyone have a solution?
COMMUNITY QUESTION
PlayerId not returning value when i try to print it (why does the roblox api never actually help?)
1 answer
Your issue is probably that you're trying to use a Localscript in the Workspace, which doesn't work. You should use normal scripts for most things that you want everyone to see, and Localscripts are mainly used for things like GUIs that are unique to each player.
I think this should work:
local Players = game:GetService("Players")
local brick = script.Parent
local yourUserId = 1108976841
local debounce = false
brick.Touched:Connect(function(hit)
-- make sure the brick was not touched too recently
if not debounce then
-- make sure it was a player that touched the brick
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
-- now we know a player touched it, but we need to make sure it was you
if player.UserId == yourUserId then
debounce = true
brick.BrickColor = BrickColor.random()
wait(1) -- time until the brick can be changed again
debounce = false
end
end
end
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.
