local function onTouch(hit)
game.Workspace.Part.BrickColor = BrickColor.new("Mid gray")
end
No errors?
local function onTouch(hit)
game.Workspace.Part.BrickColor = BrickColor.new("Mid gray")
end
No errors?
Problem: (Re-edited - August 18/08/2021)
Solution/Description:
Make sure you call the function or the function would not know what to do since you haven't actually called it.
Add a Touched event to detect whether a player has actually touched a part, because, by your question, I'm pretty sure that's what you're trying to accomplish!
Recommendation(s)
It's also best to use a debounce, to prevent the code from running too many times!
Fixed Script:
local debounce = true
local part = workspace.Part
local function onTouch(hit)
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and debounce then
debounce = false
wait(1)
part.BrickColor = BrickColor.new("Mid gray")
debounce = true
end
end)
end
onTouch() -- calling the function
Place this script in the Workspace aswell as the part, and you should be set!
I normally don't edit answers like this, especially if they're over one year old, but I'm editing this because of grammatical issues, better description, and improved code for newer developers.
it didnt work error15:54:25.647 - Workspace.Part.Script:6: Expected 'end' (to close 'function' at line 2), got ; did you forget to close 'then' at line 3?
edited try again.
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
Also make sure it is in a server script.