Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i make a IF PART CLICKED RUN A LOCAL SCRIPT?

soooo i am making a roblox horror game and i have made a script.

the script is suposed to run a local script after being clicked...

but the local script wont run after watching many tutorials on youtube.

please help me.

i really want to finish my game

ALL CODE USED:

USES REMOTE EVENTS

if clicked normal script{

local RS = game:GetService("ReplicatedStorage")
local ButtonClicked = RS:WaitForChild("PlayButtonShow")

function Clicked(Player)
	local button = script.Parent.PlayButton:Clone()
	button.Parent = Player.PlayerGui
	ButtonClicked:FireClient()
end

script.Parent.ClickDetector.MouseClick:Connect(Clicked)

}

local script{

local RS = game:GetService("ReplicatedStorage")
local ButtonClicked = RS:WaitForChild("PlayButtonShow")

function Run()
	game.StarterPlayer.CameraMaxZoomDistance = 10
	game.StarterPlayer.CameraMinZoomDistance = 10
end

ButtonClicked.OnClientFunction:Connect(Run)

}

2 comments

0

Is this a RemoteEvent or a RemoteFunction? Where is the local script located?

0

the local script is in a file i made and i uses a remote event and put it in replicated storage

2 answers

The problem is that you are changing the StarterPlayer CameraMaxZoomDistance and CameraMinZoomDistance.

You need to change the LocalPlayers CameraMaxZoomDistance and CameraMidZoomDistance.

Otherwise, you will not notice a change.

1 comment

0

i tried that

A few problems here

local RS = game:GetService("ReplicatedStorage")
local ButtonClicked = RS:WaitForChild("PlayButtonShow")

function Clicked(Player)
    local button = script.Parent.PlayButton:Clone()
    button.Parent = Player.PlayerGui
    ButtonClicked:FireClient(Player) -- You weren't being specific on what client you want to fire. 
end

script.Parent.ClickDetector.MouseClick:Connect(Clicked)

Local script:

local RS = game:GetService("ReplicatedStorage")
local ButtonClicked = RS:WaitForChild("PlayButtonShow")
local player = game.Players.LocalPlayer -- Get the localplayer

function Run()
    player.CameraMaxZoomDistance = 10 -- Replace StarterPlayer with the player
    player.CameraMinZoomDistance = 10
end

ButtonClicked.OnClientEvent:Connect(Run) -- I am sure it is suppose to be OnClientEvent...

4 comments

0

it didnt work :(

0

do i put the RemoteEvent in replicated storage

0

oFc, i thought you already put it??

0

i did out it

This discussion is preserved as it was. New answers, comments, and votes are closed.