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

how change player properties on click?

Here's what I have so far....

in a normal script

function speedUp (part)
local humanoid = part.Parent:FindFirstChild("Humanoid")
if humanoid then
	humanoid.WalkSpeed = 16*4
	
end	
end
script.Parent.Touched:Connect(speedUp)

2 comments

0

This works when you touch it with your character, not when you click it

0

I know

2 answers

Looking at the API for MouseClick, we see that when someone clicks, it returns the player. What we could do is, get the character from the Player instance by using Player.Character.

This script goes in the ClickDetector

--[[
	Normal Script
]]

local clickdetector = script.Parent

clickdetector.MouseClick:Connect(function(player)
	if player.Character then -- checks char
		local humanoid = player.Character:FindFirstChild("Humanoid") -- find humanoid
		
		if humanoid then -- if the humanoid is there
			humanoid.WalkSpeed = 100 -- change speed
		end
	end
end)

The Click Detector has a parameter for the character already. Also you can't use LocalPlayer on a Server Script because it returns nil. So use the Click Detector's parameter.

function ChangePlayerProperties(click)
	if click.Character:FindFirstChild("Humanoid") then
		click.Character.Humanoid.WalkSpeed = 100
	end
end

workspace.clicker.ClickDetector.MouseClick:Connect(ChangePlayerProperties)

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