✓ Accepted answer
It appears as if you're new to scripting, so here is a list of improvements to your code.
- When calling functions (like
Play and stopsound as in your example) you need to use parenthesis (which are these: ()) in order for the compiler to read them as function calls. Using only Play and stopsound will make the compiler think you're referring to the variables associated with the functions, not the function call itself. As an append to the previous statement, if you do not have these functions defined, you can define them using the function command:
function Play(args)
end
function stopsound(args)
end
- When verifying that two values are equal to one another, use two equal signs instead of one. One equal sign specifies assignment in Lua; two specify the conditional syntax of equal to. For example:
a = 5
b = 10
if a == b then
print(a + b)
end
b = b / 2
if a == b then
print(a + b)
end
Make sure that all of your functions, loops, and statements have ends. Roblox normally does this for you, but it's good practice in case IntelliSense (the UI and auto-filler of the script editor) doesn't pick up on it. I mention this because your first and third if statements have no ends tied to them.
The format rbxassetid://ID, with ID being the desired audio ID in your case, is a Content object and must be specified as a string. This means LocalSoundId should be set to "rbxassetid://6490981787", not just rbxassetid://6490981787.
Referring to your commented section, don't try using script signals as booleans. They should be treated as signals; in order to link to a signal, use Connect() from the signal. Also, use CanTouch.Value instead of CanTouch because you're trying to set a userdata value to a boolean.
When scripting, remember that practice makes perfect. If you want to get better, absorb the necessary information and practice.
1 comment
Thankyou for your help :)