Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
1

How do I make it so if you are not touching the part anymore you cannot effect it?

Asked by 6 days ago

This is how the script should work: If you are touching the part and clicking, the size will go down by .01 stud. If you are not touching the part anymore, nothing should happen even when you're clicking.

This is the script:

function onTouch(hit)
    mouse.Button1Down:Connect(function()
    if hit.Name == "Block" then
        hit.Size = hit.Size - Vector3.new(0.01, 0.01, 0.01)
        end
    end)
end
script.Parent.Touched:Connect(onTouch)

1 answer

Log in to vote
0
Answered by
gioni01 1494 Moderation Voter
6 days ago
Edited 6 days ago

There could be a couple of issues here. Either...

  • You're using a Local Script in workspace

  • You're attempting to get the player's mouse through a Server Script

Either way, I'll solve those for you here. To accomplish this, you'll simply need to get the local script out of workspace and put it somewhere it can actually run, like StarterPlayerScripts.

--Local Script

local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent") --wait for remote
local trigger = workspace.Part
local CanScale = false

trigger.Touched:Connect(function(part)
   CanScale = true
end)

trigger.TouchEnded:Connect(function(part)
   CanScale = false
end)

mouse.Button1Down:Connect(function()
   if CanScale then
      RemoteEvent:FireServer(trigger) --send the part so we dont have to get it on the server. this just saves you from changing another line of code in case you change the part
   end
end)

--Server script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = Instance.new("RemoteEvent") --create remote
RemoteEvent.Parent = ReplicatedStorage

RemoteEvent.OnServerEvent:Connect(function(plr,part) --first parameter always player
   part.Size = part.Size - Vector3.new(.01,.01,.01)
end)

Resources:

Remote Events


Accept and upvote if this helps!

1
not bad incapaxian 1315 — 6d
0
thank u brother incatrash gioni01 1494 — 6d
Ad

Answer this question