So in my game its supposed to be a family game i'm trying to make a part that changes your size like the one in meepcity. Can someone help me? Here is my script and sorry if your a good scripter and think its stupid.I'm still a beginner at scripting and btw i got a script from somewhere and it made my character either fall or lean back when walking so please make sure it dont do that
script:
script.Parent.Touched:connect(function(part) game.Players.LocalPlayer.Character.Humanoid.BodyHeightScale.Value = 0.5 end)
Script.Parent.Touched:Connect(function(hit) If hit.Parent:FindFirstChild(“Humanoid”) then game.Workspace[hit.Parent.Name].Humanoid.BodyHeightScale.Value = 0.5 end)
Expiation: In the ruction a have made a variable called hit, so whenever I reference hit it means the thing that was touched. After this I have checked the Parent of the hit to see if it’s a humanoid. After that I went into the workspace and located the character, lowering its height.
I did this on a mobile device so I can not test it.
Also you can only use the local player statement in a local script.
Also make sure this is a sever script.
If you need anymore help just ask.
Also DO NOT ever take scripts from other people, you won’t learn anything!
Ok, so first off, I see that you are using the object LocalPlayer
in your script. Since you can only access it in a LocalScript
, I am going to assume you are using a LocalScript
. This is a big problem (if you are using a LocalScript
), because if you use a LocalScript
to operate your body scaling content for your game, it will only show the person who touches the part scaled, and others will see them as the size they used to be before they touched the part. This is because anything done in LocalScripts
(except for a few exceptions like animations
) will not be replicated to the server, at least not properly or in the right way. So here is some advice: Use a ServerScript
. That way, it will replicate to all players
, not just one player
. Another thing is your code is just simply not correct. If you look at the touched event, the part
parameter is not being used. Lowercase Connect
is also deprecated, you need to be using capitalized Connect
. It may not seem like a big deal, but it is. One more thing is that line 2
is not the right way to be scaling
the player
in a touched event
. I will show you a better method
. So, this method
requires the parameter
you put in your function earlier but did not use. This part involves the actual fixing of your code. So, you did use a touched event. That is correct. The code in your touched event was not correct.
So, lets think about the parameter for a moment. As it says on the Roblox Developer Hub, there is a parameter called "OtherPart". If the character's body parts are the ones touching the Basepart, then we reference their entire body and find their humanoid, which we can then scale their body from. So, this is the code:
local BasePart = script.Parent function Scale(otherPart) local Character = otherPart.Parent --otherPart will be player's body part that touches local Humanoid = Character:FindFirstChild("Humanoid") if Humanoid then --checks if humanoid exists local HeightScale = Humanoid:FindFirstChild("BodyHeightScale") HeightScale.Value = 0.5 end end BasePart.Touched:Connect(Scale)
This should work. I might have forgot to add something, but other than that it should would. Accept this answer if this helps!
script.Parent.Touched:Connect(function() script.Parent.Size = Vector3.new(x,y,z) wait(2) script.Parent.Size = Vector3.new(x,y,z) end)